intlNumber
intlNumber(value, options?) formats numeric values with locale-aware number patterns. Use this for price, percentage, metrics, compact values, and measurement units.
Native reference: Intl.NumberFormat
Signature
ts
1function intlNumber(2 value: number,3 options?: Intl.NumberFormatOptions & {4 locale?: string5 scope?: IntlRuntime6 }7): stringInvalid numbers return ''.
Option map
| Option | Type | Default | Effect |
|---|---|---|---|
locale | string | runtime locale | One-off locale override |
scope | IntlRuntime | getIntl() | Use runtime locale |
style | decimal | currency | percent | unit | decimal | Formatter mode |
currency | string | undefined | Required for style: 'currency' |
unit | string | undefined | Required for style: 'unit' |
unitDisplay | short | narrow | long | short | Unit label size |
currencyDisplay | symbol | code | name | narrowSymbol | symbol | Currency label form |
signDisplay | auto | always | never | exceptZero | auto | Sign behavior |
minimumIntegerDigits | number | 1 | Integer width |
minimumFractionDigits | number | locale default | Fraction floor |
maximumFractionDigits | number | locale default | Fraction cap |
minimumSignificantDigits | number | 1 | Min significant digits |
maximumSignificantDigits | number | locale default | Max significant digits |
roundingPriority | auto | morePrecision | lessPrecision | auto | Precision control |
roundingMode | ceil | floor | expand | trunc | halfCeil | halfFloor | halfExpand | halfEven | locale default | Rounding behavior |
roundingIncrement | 1 | 2 | 5 | ... | 1 | Rounding step |
trailingZeroDisplay | auto | stripIfInteger | auto | Strip trailing zeros |
notation | standard | scientific | engineering | compact | standard | Compact/engineering mode |
compactDisplay | short | long | short | Compact output style |
useGrouping | boolean | 'auto' | 'always' | true | Group separator |
numberingSystem | string | runtime default | Digit system |
Examples
Common modes
ts
1intlNumber(1299.99, { locale: 'en-US' }) // "1,299.99"2intlNumber(1299.99, { locale: 'en-US', style: 'currency', currency: 'USD' })3intlNumber(0.42, { style: 'percent' })4intlNumber(1_234_567, { style: 'unit', unit: 'kilometer', unitDisplay: 'long' })Precision control
ts
1intlNumber(1.2345, {2 maximumFractionDigits: 2,3 minimumFractionDigits: 2,4})5 6intlNumber(1500, { style: 'compact', compactDisplay: 'short' })7intlNumber(0, { notation: 'scientific' })Signed values and locales
ts
1intlNumber(-12, { signDisplay: 'always' })2intlNumber(1_200.5, { locale: 'de-DE', style: 'currency', currency: 'EUR' })Runtime-specific usage
ts
1import { createIntl, intlNumber } from '@beforesemicolon/intl'2 3const scoped = createIntl({ locale: 'ar-EG', messages: {} })4 5intlNumber(1299.99, { scope: scoped, style: 'currency', currency: 'EGP' })6intlNumber(1299.99, { scope: scoped, currency: 'EGP', style: 'currency' })Empty/invalid output
ts
1intlNumber(NaN) // ''2intlNumber('12' as unknown as number) // ''