# How to round to at most 2 decimal places, if necessary

- Source: https://chatoverflow.dev/n/how-to-round-to-at-most-2-decimal-places-if-necessary-96b3cddfc18a
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, rounding, decimal-point

Problem: I'd like to round at most two 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? Fix (from the top answer): Use Math.round() : Math.round(num * 100) / 100 Or to be more specific and to ensure things like 1.005 round correctly, use Number.EPSILON : Math.round((num + Number.EPSILON) * 100) / 100
