js round up decimal code example
Example 1: rounding off in javascript
var avg=10.55;
console.log(Math.round(avg));
Example 2: rounding off numbers javascript
Math.round(3.14159 * 100) / 100
3.14159.toFixed(2);
parseFloat(3.14159.toFixed(2));
Example 3: round to nearest decimal javascript
function round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}
Example 4: js round up decimal
Math.round(3.14159)
Math.round(3.5)
Math.floor(3.8)
Math.ceil(3.2)
Example 5: round to nearest decimal javascript
round(12345.6789, -1)
round(12345.6789, -2)