Rounding and precision

Calculator Rounding and Precision Policy: 20 Boundary Tests

A reusable precision contract and twenty executed decimal fixtures for keeping calculator inputs, raw results, displayed values and downstream records consistent.

Direct answer

Write a calculator precision contract before choosing a rounding function. Normalize each input to a named unit, retain the documented internal precision, avoid repeated intermediate rounding unless the model requires it, and round only at an explicit display, storage or transfer boundary. Name the tie rule and decimal scale, retain enough raw context to reproduce the result, and test midpoint, sign, carry, percentage, locale, range and invalid-input cases after every relevant change.

Definition

A calculator rounding policy is the explicit contract that separates input normalization, internal representation, intermediate calculation, stored raw values and user-facing display values, while naming the scale and tie-breaking rule at every boundary that rounds.

Key findings

Verified 16 September 2026

  • Precision is a contract, not a visual preference: the input unit, internal representation, rounding stage, display scale and stored value must be stated together.
  • ECMAScript Number uses IEEE 754 binary64 and includes positive and negative zero, so decimal-looking inputs and visible zero need explicit test cases.
  • Rounding every intermediate line can create a different final result from rounding once at the approved output boundary.
  • The interface must identify invalid, missing and out-of-range input instead of silently converting it to zero or leaving a stale result visible.

What belongs in a calculator rounding policy?

The policy should name the accepted input syntax and unit, the internal numeric representation, the allowed input scale, every intermediate-rounding rule, the final display scale and tie mode, the stored raw and displayed values, the locale-formatting step, valid bounds, and the formula and policy version. A statement such as ‘round to two decimals’ is incomplete because it does not say when or how a midpoint is resolved.

NIST's SI guide distinguishes a quantity from its numerical value and stresses unambiguous unit expression. It also treats percent as the number 0.01. For a calculator, that makes the input contract consequential: 12.5 percent must be normalized deliberately to 0.125 before the formula, not guessed from the label after calculation.

Minimum rounding-policy manifest
FieldRequired decisionExample for this reference model
InputSyntax, unit, scale and valid rangeCanonical decimal string; unit named beside field
InternalRepresentation and intermediate ruleExact decimal fixture model; no undocumented line rounding
OutputBoundary, scale and midpoint modeFinal display at two decimals; half away from zero
StorageRaw, display and version fieldsNormalized inputs, raw result, displayed result, formula/policy version
LocaleParsing versus formattingNormalize first; format only after the numeric result is fixed
FailureMissing, invalid and out-of-range behaviorText error, no stale result and no silent zero

Why should JavaScript calculators test decimal boundaries explicitly?

The current ECMAScript specification defines Number as IEEE 754 binary64. Many decimal fractions do not have an exact finite binary representation, and the type has distinct positive and negative zero values. That does not make JavaScript unsuitable for calculators; it means the model must choose and test an appropriate representation and boundary policy instead of treating a displayed decimal as proof of an exact internal decimal.

The published fixture runner therefore accepts canonical decimal strings and applies one declared decimal rule. This makes values such as 2.675, -2.675 and 999.995 deterministic for the evidence asset. It is an example policy, not a claim that half away from zero is universally correct; tax, accounting, measurement or contractual rules may require another mode.

Which twenty boundary cases should be replayed?

The table records expected and observed output for the reference rule. P01 to P20 all passed on 16 September 2026. Range rejection, missing input and nonnumeric input remain interface-level release gates rather than fabricated numeric outputs.

Twenty executed exact-decimal rounding fixtures
IDBoundaryInput and policyExpected and observed
P01Trailing zero2.500 to 2 places2.50 — passed
P02Repeating source0.333333 to 2 places0.33 — passed
P03Positive midpoint2.675 to 2 places2.68 — passed
P04Binary-looking residue0.30000000000000004 to 2 places0.30 — passed
P05Positive zero0 to 2 places0.00 — passed
P06Negative zero-0.000 to 2 places0.00 — passed
P07Negative midpoint-2.675 to 2 places-2.68 — passed
P08Carry across thousands999.995 to 2 places1000.00 — passed
P09Small valid value0.004 to 3 places0.004 — passed
P10Small display value0.004 to 2 places0.00 — passed
P11Large value below midpoint999999999999.994 to 2 places999999999999.99 — passed
P12Large-value carry999999999999.995 to 2 places1000000000000.00 — passed
P13Normalized percent0.125 to 3 places0.125 — passed
P14One basis point0.0001 to 4 places0.0001 — passed
P15Currency midpoint12.345 to 2 places12.35 — passed
P16No premature carry30.8746 to 2 places30.87 — passed
P17Annual aggregation30874.999 to 2 places30875.00 — passed
P18Locale-independent value1234.5 to 2 places1234.50 — passed
P19Retained currency zero47.500 to 2 places47.50 — passed
P20Negative half cent-0.005 to 2 places-0.01 — passed

How should intermediate rounding be handled?

Round at a model boundary, not merely because a line is visible in the interface. If a fictional annual-cost calculator multiplies 12.5 hours by $47.50 and 52 weeks, the direct result is $30,875.00. Rounding the weekly subtotal to a whole dollar first would produce $30,888.00, a $13 difference created only by an undocumented intermediate boundary.

Sometimes line-level rounding is the business rule—for example, an invoice contract may require each item or tax line to settle independently. In that case the manifest should name the line boundary and its mode, and the fixtures should reconcile both the line results and final total.

Worked fictional annual-cost example
PathCalculationDisplayed annual result
Approved reference12.5 × 47.50 × 52, then final display$30,875.00
Undocumented intermediate roundingRound 593.75 weekly to 594, then × 52$30,888.00
DifferenceCreated by rounding stage, not changed inputs$13.00

How should locale, storage and exports stay consistent?

Parsing and formatting are separate. Normalize an allowed locale string to one canonical numeric value, run the formula, then format the fixed result for the chosen locale. Never remove punctuation heuristically in a way that could turn 1,234 into either 1234 or 1.234 without a declared locale.

A downstream record should retain normalized inputs, unit identifiers, the raw result or reproducible operands, the displayed result, the formula version and the rounding-policy version. The exported display value must reconcile with what the visitor saw; a CRM or CSV must not independently reround the same raw value under an unnamed rule.

Which failures should block publication?

Block release when an invalid or missing input becomes zero, a percentage is interpreted both as 12.5 and 0.125, a midpoint changes between surfaces, negative zero appears as a confusing debt or loss, an intermediate line rounds without a stated rule, locale parsing changes magnitude, a stored or exported result cannot reproduce the visible answer, or a stale result remains after input becomes invalid.

W3C form guidance calls for labels, instructions, validation and clear notifications. A calculator should identify the affected field and tell the user how to correct the value; color alone or a silently cleared result is not sufficient feedback.

Method and evidence

Evidence type: Reusable rounding-policy manifest and twenty executed exact-decimal boundary fixtures

  1. Defined one fictional reference policy that normalizes decimal input, calculates without undocumented intermediate rounding, and applies decimal half away from zero only at a named output boundary.
  2. Executed twenty deterministic string-to-decimal fixtures so midpoint expectations do not depend on an ECMAScript binary floating-point approximation.
  3. Separated arithmetic results from locale formatting, field validation and downstream storage because each boundary can otherwise change the value independently.
  4. Checked current primary standards without claiming a named calculator builder, browser, finance system or regulated model was tested.

Topic score: 4.62 / 5. Business fit 4.8, verified demand 4.4, distinct intent 4.8, original evidence 4.8, citation usefulness 4.5, feasibility 4.4.

Primary sources

Limitations

  • This is an engineering test template, not accounting, tax, financial, legal or metrology advice.
  • Half away from zero is the declared rule for the fictional fixtures, not a universal recommendation; applicable domain rules may require half even, directed rounding or another method.
  • The exact-decimal reference runner validates the published expectations, not a named calculator builder, browser, database, CRM, currency library or assistive technology.
  • Formatting a value to two decimals does not by itself prove the internal model, stored record or downstream export used the same policy.

Verification and corrections

Current NIST quantity-expression, ECMAScript Number and W3C accessible-form guidance plus twenty deterministic decimal fixtures verified 16 September 2026.

Recommended retest: Replay every fixture after a formula, numeric runtime, currency, unit, locale, storage-scale or export-format change.

Found an error or a changed standard? Use the correction process and include the page URL and primary evidence.

Next step

Apply the evidence to your next release

Use the published method, keep a dated test record and revisit the result after the calculator or its operating rules change.

Open the testing protocol