javascript - how to round to nearest integer [duplicate]
Possible Dupl开发者_如何转开发icate:
How can I round of to whole numbers in JavaScript?
In javascript is there a function which allows me to round to the nearest integer? Either up or down.
So:
2.1 = 2 2.9 = 3 4.5 = 5 1.1 = 1
Use Math.round(number)
:
var i = Math.round(2.1);
Math.round(x)
and Math.floor(x)
both documented here
use Math.round()
EDIT:
Mine was wrong the one above me is correct
精彩评论