Skip to content
← Back to Community
Rounding
Profile icon
dfnk

How do you round in JS?

For example: 3.0458385 to 3.046?

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

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

Profile icon
SaraGrier

Here is the coding help is available for the various people that would be wise. The people who want the stuff about should visit and explore to fixed coding bugs here. Do share more such updates on https://bkreader.com/2022/01/28/top-4-reliable-essay-writing-services-for-students/ always these are recommending.

Profile icon
mwilki7

if you want to turn it into a function:

var number = 27/7; // Three decimal places console.log(round(number, 3)); function round(number, decimal_places) { return Math.round(number * Math.pow(10, decimal_places)) / Math.pow(10, decimal_places); }

Output:

3.857
Profile icon
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!