Js rounds the mathematical function round to use the instance

  • 2020-03-30 02:52:02
  • OfStack

The round function in js can be used to round Numbers, and it computes the first number after the decimal point.
Round round round round round round round round round round round round round round round round round round round


Math.round(number)

Here are some examples:

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

Round is rounded only to the first decimal place. If we want to round to the rest of the decimal place, we can multiply the number by a multiple of 10 and divide round by the same number:

var my_val=11.257;
var my_val=11.254;
document.write(Math.round(my_val*100)/100);
//print 11.25


Related articles: