The Math.round()
function returns the value of a number rounded to the nearest integer.
Math.round(x) // x is a number.
let a = Math.round( 20.49); // 20 console.log(a);/* www . j a va 2s. c o m*/ a = Math.round( 20.5 ); // 21 console.log(a); a = Math.round( 42 ); // 42 console.log(a); a = Math.round(-20.5 ); // -20 console.log(a); a = Math.round(-20.51); // -21 console.log(a); console.log(Math.round(25.9)); // 26 console.log(Math.round(25.5)); // 26 console.log(Math.round(25.1)); // 25