How rounding to decimal places works
To round at a chosen decimal place, the value is first scaled up by a power of ten so the place you care about lands in the ones column. The chosen rule is applied to that scaled number, and then it is scaled back down. Rounding to two places, for instance, multiplies by 100, rounds, and divides by 100.
This same mechanism works for any number of places, including zero, which rounds to a whole number.
Choosing a rounding mode
The three modes differ in which direction they push a value. Picking the right one matters whenever the discarded digits could change a decision, such as in pricing, capacity planning or grading.
- Round (nearest) goes to whichever option is closer, with ties going up
- Floor always moves toward the lower value, so 2.99 becomes 2
- Ceil always moves toward the higher value, so 2.01 becomes 3
- Floor and ceil ignore distance entirely and only follow direction
Where each mode fits
Rounding to nearest is the everyday default for reporting figures cleanly. Floor and ceil are most useful when only whole units make sense or when you must stay safely on one side of a limit.
- Use ceil when you cannot exceed a budget or need enough containers
- Use floor when partial units do not count, such as completed laps
- Use nearest for general-purpose display and averages
Caveats with binary floating point
Computers store decimals in binary, so a few values that look exact are not stored exactly. This can occasionally make a tie round in an unexpected direction or shift a final digit by one. The effect is tiny and only shows up at the very last decimal place.
If perfectly predictable rounding of money is critical, work in the smallest whole unit such as cents and round at zero decimal places to sidestep the issue.
Formula
rounded = mode(value · 10^places) / 10^places
