Monday, June 24, 2019

javascript - Round to at most 2 decimal places (only if necessary)



I'd like to round at most 2 decimal places, but only if necessary.



Input:



10
1.7777777
9.1



Output:



10
1.78
9.1


How can I do this in JavaScript?


Answer




Use Math.round(num * 100) / 100


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...