javascript round to 2 digits
var numb = 123.23454;
numb = numb.toFixed(2);var num = 2;
var roundedString = num.toFixed(2);// 2.00let num = 12.5452411;
num = num.toFixed(3); // 12.545var totalAmount = 0;
totalAmount = Number($("#sub_amount").val()) + Number($("#vat_amount").val());
totalAmount = totalAmount.toFixed(2);
$('#total_amount').val(totalAmount);
//@sujayconst roundTo = function(num: number, places: number) {
const factor = 10 ** places;
return Math.round(num * factor) / factor;
};
roundTo(123.456, 2); // 123.46
roundTo(123.3210, 2); // 123.32
roundTo(123.456, 1); // 123.5
roundTo(123, 2); // 123
Also in JavaScript:
- mixin in styled components
- delete character between index
- standalone form inside reactive form
- registeing components in vue
- jquery remove disabled property from button
- Programação web com Node e Express Beneficiando-se da stack JavaScript
- component unmount useeffect
- expressjs cheat sheet
- Object destructuring
- discord.js v12 how to set owner commands
- add items to a react array in hooks
- instantiate js
- react how to pass the input target value
- js know size of screen
- interval javascript
- javascript change select options dynamically
- javascript string get last two character
- jquery add text to textbox
- how to set default value in input field in angularjs
- javascript read json file
- how to use function in javascript
- how to check if json data is received in ajax response
- generate id js
- javascript variables