With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Solved

Posted on 1999-01-21

How can you use math.round or a like object to round a number to two decimal places. Could I make this a function? How?

1 Comment

However, consider this...

1. if you were to multiple the number by 100

i.e. 3.1435030 * 100 = 314.35030

2. then round it up

Math.round(314.35030), you will get 314

3. now, divide it back by 100

i.e. 314 / 100 = 3.14

4. there you go, your answer is 3.14 (rounded to the nearest 2 decimal places.

so, the function you are looking for is:

function myRound( number , places )

{

//heh, I forgot how to do the exponential, so don't laugh :)

var factor = 10;

for (var i = 0;i < places;i++) factor *= factor

return (Math.round(number * factor))/factor

}

to round it to 3 decimal places, call it as:

myNumber = myRound(number_to_round,3)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Course of the Month12 days, 21 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.