How to round off a no. to the nearest specified decimal value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

How to round off a no. to the nearest specified decimal value

18th Mar 2017, 8:19 AM
Utkαrsh
Utkαrsh - avatar
4 Answers
+ 16
Hey bro do this:- Lets take a number 1.778890 Write this code-- var n=Math.round(1.778890*10)/10; document.write(n); If you want 2 decimal places then write 100 instead of 10 and if 3 decimal then 1000 And so on...(^_^)
18th Mar 2017, 10:54 AM
Nikhil
Nikhil - avatar
+ 15
The JS Math round() is useful in this Example:- Math.round(6.7); Output:- 7
18th Mar 2017, 8:59 AM
Nikhil
Nikhil - avatar
+ 8
that worked. thanks Buddy .
18th Mar 2017, 12:36 PM
Utkαrsh
Utkαrsh - avatar
+ 7
@nikhil but I want the no. to be rounded off to three decimal points Math.round removes the decimal Example :- 6.8937572817375 Round off :- 6.894
18th Mar 2017, 10:45 AM
Utkαrsh
Utkαrsh - avatar