DEV Community

Nagarajan R
Nagarajan R

Posted on

Answer: Round to at most 2 decimal places (only if necessary)

Use Math.round(num * 100) / 100

Edit: to ensure things like 1.005 round correctly, we use

Math.round((num + Number.EPSILON) * 100) / 100

Top comments (0)