ajya ajya - 6 months ago 35
Javascript Question

How to do two decimal places roundup in java script

input:

11
2.7777777
8.1


Output:

11
2.78
8.1


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

How can I do this in JavaScript?

Answer

Use Math.round(num * 100) / 100