The round function in JS can be used to round up a number, which is calculated for the first digit after the decimal point.
The round function can be rounded, it is a rounding function, the following is a look at the syntax of round:
Copy Code code as follows:
Math.Round (number)
Let's look at a few examples:
Copy Code code as follows:
document.write (Math.Round (2.65));//Print 3
document.write (Math.Round (7.05));//Print 7
document.write (Math.Round ( -2.65));//Print-3
document.write (Math.Round ( -8.15));//Print-8
document.write (Math.Round (11.65));//Print 12
The rounding of the round function is only for the first digit after the decimal point, and if you want to target the rest of the decimal point, we can multiply the number by 10, and then divide the round by the same number:
Copy Code code as follows:
var my_val=11.257;
var my_val=11.254;
document.write (Math.Round (my_val*100)/100);
Print 11.25