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.
| Field | Required decision | Example for this reference model |
|---|---|---|
| Input | Syntax, unit, scale and valid range | Canonical decimal string; unit named beside field |
| Internal | Representation and intermediate rule | Exact decimal fixture model; no undocumented line rounding |
| Output | Boundary, scale and midpoint mode | Final display at two decimals; half away from zero |
| Storage | Raw, display and version fields | Normalized inputs, raw result, displayed result, formula/policy version |
| Locale | Parsing versus formatting | Normalize first; format only after the numeric result is fixed |
| Failure | Missing, invalid and out-of-range behavior | Text 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.
| ID | Boundary | Input and policy | Expected and observed |
|---|---|---|---|
| P01 | Trailing zero | 2.500 to 2 places | 2.50 — passed |
| P02 | Repeating source | 0.333333 to 2 places | 0.33 — passed |
| P03 | Positive midpoint | 2.675 to 2 places | 2.68 — passed |
| P04 | Binary-looking residue | 0.30000000000000004 to 2 places | 0.30 — passed |
| P05 | Positive zero | 0 to 2 places | 0.00 — passed |
| P06 | Negative zero | -0.000 to 2 places | 0.00 — passed |
| P07 | Negative midpoint | -2.675 to 2 places | -2.68 — passed |
| P08 | Carry across thousands | 999.995 to 2 places | 1000.00 — passed |
| P09 | Small valid value | 0.004 to 3 places | 0.004 — passed |
| P10 | Small display value | 0.004 to 2 places | 0.00 — passed |
| P11 | Large value below midpoint | 999999999999.994 to 2 places | 999999999999.99 — passed |
| P12 | Large-value carry | 999999999999.995 to 2 places | 1000000000000.00 — passed |
| P13 | Normalized percent | 0.125 to 3 places | 0.125 — passed |
| P14 | One basis point | 0.0001 to 4 places | 0.0001 — passed |
| P15 | Currency midpoint | 12.345 to 2 places | 12.35 — passed |
| P16 | No premature carry | 30.8746 to 2 places | 30.87 — passed |
| P17 | Annual aggregation | 30874.999 to 2 places | 30875.00 — passed |
| P18 | Locale-independent value | 1234.5 to 2 places | 1234.50 — passed |
| P19 | Retained currency zero | 47.500 to 2 places | 47.50 — passed |
| P20 | Negative 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.
| Path | Calculation | Displayed annual result |
|---|---|---|
| Approved reference | 12.5 × 47.50 × 52, then final display | $30,875.00 |
| Undocumented intermediate rounding | Round 593.75 weekly to 594, then × 52 | $30,888.00 |
| Difference | Created 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
- 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.
- Executed twenty deterministic string-to-decimal fixtures so midpoint expectations do not depend on an ECMAScript binary floating-point approximation.
- Separated arithmetic results from locale formatting, field validation and downstream storage because each boundary can otherwise change the value independently.
- 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
- NIST Guide to the SI, Chapter 7 ↗Primary guidance on unambiguous quantities, units and percentages; checked 16 September 2026.
- ECMAScript language types and Number ↗Primary specification for binary64 Number values, infinities and signed zero; checked 16 September 2026.
- ECMAScript Math.round ↗Primary specification for the built-in integer-rounding operation; checked 16 September 2026.
- W3C Forms Tutorial ↗Primary guidance for labels, instructions, input validation and notifications; checked 16 September 2026.
- W3C User Notifications ↗Primary guidance for clear, correctable and programmatically exposed errors; checked 16 September 2026.
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