Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  114] [ 7]  / answers: 1 / hits: 19551  / 13 Years ago, wed, august 24, 2011, 12:00:00

Possible Duplicate:

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


More From » math

 Answers
39

Use Math.round(number):



var i = Math.round(2.1);

[#90448] Tuesday, August 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;