Simple:
var x = 3.50; Math.round(x);
// Output: 4 |
Simple (negative):
var x = -3.40; Math.round(x);
// Output: -3 |
Rounded upwards:
var x = 5.25; Math.ceil(x);
// Output: 6 |
One decimal:
var x = 5.26; Math.round(x*10)/10;
// Output: 5.3 |
Two decimals:
var x = 6.789323; Math.round(x*10)/10;
// Output: 6.79 |
Try it yourself below using this simple form (use the dot as a decimal separator):
Here's a shortcut to this page if you should find it useful and would like an easy address to remember it by:
-