Link Search Menu Expand Document

getNumberFormatter() function

Returns a number formatter function for the given locales and number skeleton


export declare function getNumberFormatter(locales: string | string[], skeleton: string | Skeleton, currency?: string | null, onError?: (err: NumberFormatError) => void): (value: number) => string;


Parameter Type Description
locales string | string[] One or more valid BCP 47 language tags, e.g. fr or en-CA
skeleton string | Skeleton An ICU NumberFormatter pattern or ::-prefixed skeleton string, or a parsed Skeleton structure
currency string | null If skeleton is a pattern string that includes ยค tokens, their skeleton representation requires a three-letter currency code.
onError (err: NumberFormatError) => void If defined, will be called separately for each encountered parsing error and unsupported feature.


(value: number) => string


Uses Intl.NumberFormat internally, including features provided by the Unified API Proposal.


import { getNumberFormatter } from '@messageformat/number-skeleton'

let src = ':: currency/CAD unit-width-narrow'
let fmt = getNumberFormatter('en-CA', src, console.error)
fmt(42) // '$42.00'

src = '::percent scale/100'
fmt = getNumberFormatter('en', src, console.error)
fmt(0.3) // '30%'