Q:

how to round number in js

// Use Math.ceil()
Math.ceil(1.2); // --> 2

Math.round(1.5); // --> 2
Math.round(1.4); // --> 1
Math.floor(1.8); // --> 1
9
var avg=10.55;
console.log(Math.round(avg)); //Prints 11
12
//rounds a number  to the nearest integer
Math.round(2.6); // 3
Math.round(2.49); //2
Math.round(2.5); //3
1
+3.5 => +3.0
-3.5 => -4.0

+3.5 => +3.0 using Math.floor()
-3.5 => -3.0 using Math.ceil()
0

New to Communities?

Join the community