Rounding: worked example
| Value | 3.1 |
|---|---|
| Decimal places | 2 |
| Rounded value | 3.1 |
| Difference from original | 0.00159 |
Rounding: formula
Enter a value and a whole-number count of decimal places. This implementation uses JavaScript Math.round after scaling by 10^places. Exact halfway cases go toward positive infinity: 2.5 goes to 3, but −2.5 goes to −2 at zero places.
Negative places round to tens or hundreds. This differs from both half-away-from-zero and half-to-even conventions.
Rounding: changing Value
| Value | Rounded value | Difference from original |
|---|---|---|
| 2.5 | 2.5 | 0.003 |
| 2.8 | 2.8 | -0.003 |
| 3.1 | 3.1 | 0.002 |
| 3.5 | 3.5 | -0.004 |
| 3.8 | 3.8 | 0 |
Rounding: compare input ranges
| Input | Tested from | To | Rounded value: low input | Rounded value: high input | Swing |
|---|---|---|---|---|---|
| Value | 2.8 | 3.5 | 2.8 | 3.5 | 0.63 (20%) |
| Decimal places | 1 | 3 | 3.1 | 3.1 | 0.042 (1.3%) |
Rounding: individual input comparisons
| Input | Value | Rounded value | Difference from original |
|---|---|---|---|
| Value | 2.5 | 2.5 | 0.003 |
| 2.8 | 2.8 | -0.003 | |
| 3.1 | 3.1 | 0.002 | |
| 3.5 | 3.5 | -0.004 | |
| 3.8 | 3.8 | 0 | |
| Decimal places | 0 | 3 | 0.142 |
| 1 | 3.1 | 0.042 | |
| 2 | 3.1 | 0.00159 | |
| 3 | 3.1 | -0.00041 | |
| 4 | 3.1 | -0.00001 |
Rounding: combined input changes
| Value / Decimal places | 0 | 2 | 4 |
|---|---|---|---|
| 2.5 | 3 | 2.5 | 2.5 |
| 2.8 | 3 | 2.8 | 2.8 |
| 3.1 | 3 | 3.1 | 3.1 |
| 3.5 | 3 | 3.5 | 3.5 |
| 3.8 | 4 | 3.8 | 3.8 |
Rounding: which assumptions move the result?
Rounding: values and definitions
| Quantity and definition | Value used |
|---|---|
| Value | 3.1 |
| Decimal places | 2 |
| Rounded value | 3.1 |
| Difference from original | 0.00159 |
Rounding: half and double Value
| Value | Rounded value |
|---|---|
| 1.6 | 1.6 |
| 3.1 | 3.1 |
| 6.3 | 6.3 |
Common error: Rounding a value early and then using the rounded figure in further math. A number rounded for a report is a display choice; feeding that shortened version back into another formula is a different, avoidable error.
A decimal input may have an inexact binary representation before scaling. Here 1.005 at two places produces 1.00, whereas 2.675 produces 2.68. Exact half ties follow Math.round toward positive infinity; decimal financial rules may require a different implementation.
Algebra & Arithmetic calculators: Weighted Average Calculator, 2x2 Matrix Determinant Calculator, 3x3 Matrix Determinant Calculator, Scientific Calculator, Fraction Calculator, Decimal to Fraction Calculator.
Rounding trades precision for readability, and that trade is invisible until it's chained. Round three intermediate results in a multi-step calculation and the final answer can drift measurably from what the same calculation gives using full precision throughout, because each rounding step introduces its own small error and those errors don't cancel: they usually stack.
Keep full, unrounded precision through every intermediate step of a calculation, and round only the final number that gets reported or displayed.
See scientific notation for expressing large and small numbers with significant figures, and the percent error page for measuring the effect of rounding. The mean and standard deviation calculators use unrounded data, and the sales tax calculator rounds to cents. The unit conversion pages need care with precision.
How do I round to two decimal places?
Look at the third decimal digit: if it is 5 or more, increase the second decimal by one, otherwise leave it unchanged, and drop the rest.
Should I round at each step of a calculation?
No. Keep full precision until the final answer, then round once, to avoid accumulating rounding error.
Why does 2.5 sometimes round to 2?
Some systems use round-half-to-even, sometimes called banker's rounding, to avoid bias, so 2.5 rounds to 2 and 3.5 rounds to 4.