Skip to content

Main content

Decimal Double Rounding Witness Tool

Demonstrate explicit Math.round half-toward-positive-infinity decimal rounding; this tool intentionally compares rounding policies.

Loading tool…

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

  1. Enter value, firstDigits, finalDigits. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. 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 fieldMeaning and unitsAccepted input
valueSupplied scalar or returned value under the stated operation.Required. Finite number.
firstDigitsFirst DigitsRequired. Safe integer; maximum 12.
finalDigitsFinal DigitsRequired. Safe integer; minimum 0; maximum 10.
Output fieldInterpretationReturned shape
directDirectRequired. Finite number.
stagedStagedRequired. Finite number.
differsDiffersRequired. Boolean.
json
{
  "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

  1. Calculation and input contract: number/decimal-double-rounding-witness — tool.io

  2. ECMAScript Language Specification: Math.round — Ecma International / TC39

Similar or alternative tools