Skip to content

Rounding, precision, and signs

Use the fixed-decimal preset for ordinary numeric display. Use Intl.NumberFormat in a Core template when a report needs a specific rounding or sign policy. These options change display, not arithmetic or stored values.

This example rounds the display to the nearest 0.05 major unit. Currency selection alone does not enable cash rounding:

const cash = new Intl.NumberFormat('de-CH', {
style: 'currency', currency: 'CHF',
minimumFractionDigits: 2, maximumFractionDigits: 2,
roundingIncrement: 5, roundingMode: 'halfExpand',
});
grid.columns = [{
prop: 'amount', name: 'Cash display (CHF)', readonly: true,
cellTemplate: (_h, { value }) => value == null ? '' : cash.format(value),
}];
grid.source = [{ amount: 1.02 }, { amount: 1.03 }];

These display with amounts 1.00 and 1.05; currency placement follows the locale. The source still contains 1.02 and 1.03. This illustrates an increment, not a jurisdiction’s payment or accounting rule. Put actual business rounding in your calculation layer.

Check support in the browsers you ship. Some engines silently ignore newer options. For this recipe, cash.resolvedOptions().roundingIncrement === 5 confirms the increment was recognized; do not silently substitute a different rounding policy.

Construct a formatter with { signDisplay: 'exceptZero', minimumFractionDigits: 1, maximumFractionDigits: 1 } and use the same template pattern. In en-US, 5 displays as +5.0, -5 as -5.0, and 0 as 0.0. This is useful for BI period changes. For ratio changes, also set style: 'percent' and store fractions.

These are Intl options, not fields on dataGridFormat.value:

NeedOptions and decisions
Required leading digitsminimumIntegerDigits; identifiers should usually remain text
Fixed or optional decimal placesminimumFractionDigits, maximumFractionDigits
Scientific precisionminimumSignificantDigits, maximumSignificantDigits
Combining significant and fraction limitsroundingPriority: auto, morePrecision, lessPrecision; choose deliberately
Rounding direction/tiesroundingMode: ceil, floor, expand, trunc, halfCeil, halfFloor, halfExpand, halfTrunc, halfEven
Rounding to an incrementroundingIncrement; fraction bounds must agree; cannot combine freely with significant-digit rounding
Suppress decimals for whole resultstrailingZeroDisplay: 'stripIfInteger'
Plus/minus policysignDisplay: auto, never, always, exceptZero, negative; consider negative zero
Group separatorsuseGrouping; available policies depend on runtime and notation
Currency representationcurrencyDisplay: symbol, narrowSymbol, code, name; currencySign: standard, accounting
Magnitude and labelsnotation, compactDisplay, style, unit, unitDisplay
Locale negotiation and digitslocaleMatcher, numberingSystem, or locale Unicode extensions

Specifying only one fraction bound can interact with a default for the other bound. Inspect resolvedOptions() when precision surprises you. For half-even rounding, set roundingMode: 'halfEven' with the desired precision; do not assume a binary floating-point input exactly represents a decimal tie.

See scientific notation and units for template setup, countries and locales for digits, and the ECMA-402 NumberFormat specification for allowed option combinations and runtime behavior.