Ask coding questions

← Back to all posts
Rounding
dfnk

How do you round in JS?

For example: 3.0458385 to 3.046?

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
NagasaicharanKa
Hardik416
MANAV0201
dfnk
Comments
hotnewtop
SixBeeps

Rounding to 3 decimal places looks something like this:
Math.round(x*1000)/1000

mwilki7

if you want to turn it into a function:

Output:

Bookie0

Hey I think it’s Math.round(number); and put the number where it says “number”
But here is the link I found it from: https://www.w3schools.com/jsref/jsref_round.asp

Hope this helps!