Description
Demonstrate explicit Math.round half-toward-positive-infinity decimal rounding; this tool intentionally compares rounding policies.
Decimal rounding and scale alignment depend on retained places, discarded digits, tie rules, and the number of rounding stages. A decimal spacing is different from the binary floating-point spacing of a runtime number. Text-based digit operations can preserve widths that disappear when a value is parsed numerically.
Demonstrate explicit Math.round half-toward-positive-infinity decimal rounding; this tool intentionally compares rounding policies.
When to use this tool
Use Decimal Double Rounding Witness when you need this specific decimal tie, scale, digit-carry, spacing, or staged-rounding check.
How to use the tool and how it works
- Enter value, firstDigits, finalDigits. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read direct, staged, differs. Inspect differs before interpreting the associated values.
For finalDigits in 0..10 and firstDigits from finalDigits+1 through 12 compare direct=Math.round(value*10^finalDigits)/10^finalDigits with a staged first-round-then-final-round result. Return direct, staged, and differs using exact numeric inequality.1
Math.round selects the nearest integer and resolves half ties toward positive infinity. Binary intermediate rounding is an additional reason that direct and staged decimal-place rounding can differ.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| value | Supplied scalar or returned value under the stated operation. | Required. Finite number. |
| firstDigits | First Digits | Required. Safe integer; maximum 12. |
| finalDigits | Final Digits | Required. Safe integer; minimum 0; maximum 10. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| direct | Direct | Required. Finite number. |
| staged | Staged | Required. Finite number. |
| differs | Differs | Required. Boolean. |
{
"input": {
"value": 1.249,
"firstDigits": 2,
"finalDigits": 1
},
"output": {
"direct": 1.2,
"staged": 1.3,
"differs": true
}
} Limitations and assumptions
- The example uses JavaScript rounding with half ties toward positive infinity, not ties-to-even. Binary representation, multiplication precision, and overflow affect results; this is a witness calculation rather than exact decimal monetary rounding.
- Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
- Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.
Alternative or Complementary methods
Use an exact decimal representation when binary floating-point rounding is inadequate. Apply a complete rounding rule rather than treating a tie-only flag or digit-count term as the whole decision.
References
-
Calculation and input contract: number/decimal-double-rounding-witness — tool.io
-
ECMAScript Language Specification: Math.round — Ecma International / TC39
Similar or alternative tools
- Number: Half Integer Tie Neighbor Pair
Report the integer neighbors and exact half-integer tie status of one safely bounded number without imposing a rounding policy.
- Decimal Tie To Even Parity Flag
Identify an exact discarded-decimal half tie and the retained-digit parity adjustment for ties-to-even.