NumberFormat

compactDisplay

RES
type compactDisplay = [#long | #short]

Used only when notation is #compact

currency

RES
type currency = string

An ISO 4217 currency code. e.g. USD, EUR, CNY

currencyDisplay

RES
type currencyDisplay = [ | #code | #name | #narrowSymbol | #symbol ]

currencySign

RES
type currencySign = [#accounting | #standard]

format

RES
let format: (t, float) => string

format(formatter, value) returns the formatted representation of value.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"]) formatter->Intl.NumberFormat.format(1234.5) == "1,234.5"

formatBigInt

RES
let formatBigInt: (t, bigint) => string

formatBigInt(formatter, value) formats bigint values.

formatBigIntRange

RES
let formatBigIntRange: (t, ~start: bigint, ~end: bigint) => string

formatBigIntRange(formatter, ~start, ~end) formats a range of bigint values.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatBigIntRange(~start=1n, ~end=2n) == "1–2"

formatBigIntRangeToParts

RES
let formatBigIntRangeToParts: ( t, ~start: bigint, ~end: bigint, ) => array<numberFormatRangePart>

formatBigIntRangeToParts(formatter, ~start, ~end) describes how the bigint range would be rendered.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatBigIntRangeToParts(~start=3n, ~end=4n)->Array.length > 0

formatBigIntToParts

RES
let formatBigIntToParts: (t, bigint) => array<numberFormatPart>

formatBigIntToParts(formatter, value) returns the bigint formatting broken into parts.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatBigIntToParts(5n)->Array.length > 0

formatInt

RES
let formatInt: (t, int) => string

formatInt(formatter, value) formats integer values.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatInt(42) == "42"

formatIntRange

RES
let formatIntRange: (t, ~start: int, ~end: int) => string

formatIntRange(formatter, ~start, ~end) formats integer ranges.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatIntRange(~start=1, ~end=3)->String.length > 0

formatIntRangeToParts

RES
let formatIntRangeToParts: (t, ~start: int, ~end: int) => array<numberFormatRangePart>

formatIntRangeToParts(formatter, ~start, ~end) returns how the integer range would be rendered.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatIntRangeToParts(~start=1, ~end=1)->Array.length > 0

formatIntToParts

RES
let formatIntToParts: (t, int) => array<numberFormatPart>

formatIntToParts(formatter, value) returns formatting parts for an integer.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatIntToParts(123)->Array.length > 0

formatRange

RES
let formatRange: (t, ~start: float, ~end: float) => string

formatRange(formatter, ~start, ~end) formats numbers representing a range.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"]) formatter->Intl.NumberFormat.formatRange(~start=1., ~end=2.)->String.length > 0

formatRangeToParts

RES
let formatRangeToParts: ( t, ~start: float, ~end: float, ) => array<numberFormatRangePart>

formatRangeToParts(formatter, ~start, ~end) returns how the range would be rendered.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"]) formatter->Intl.NumberFormat.formatRangeToParts(~start=1., ~end=2.)->Array.length > 0

formatString

RES
let formatString: (t, string) => string

formatString(formatter, value) interprets value as a number string and formats it.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatString("1234") == "1,234"

formatStringToParts

RES
let formatStringToParts: (t, string) => array<numberFormatPart>

formatStringToParts(formatter, value) returns formatting parts for a numeric string.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en"]) formatter->Intl.NumberFormat.formatStringToParts("123")->Array.length > 0

formatToParts

RES
let formatToParts: (t, float) => array<numberFormatPart>

formatToParts(formatter, value) breaks the formatted result into parts.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"]) formatter->Intl.NumberFormat.formatToParts(123)->Array.length > 0

ignore

RES
let ignore: t => unit

ignore(numberFormat) ignores the provided numberFormat and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

make

RES
let make: (~locales: array<string>=?, ~options: options=?) => t

Creates a new Intl.NumberFormat instance for locale-aware number formatting.

See Intl.NumberFormat on MDN.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"], ~options={style: #currency, currency: "USD"}) formatter->Intl.NumberFormat.format(1234.5) == "$1,234.50"

notation

RES
type notation = [ | #compact | #engineering | #scientific | #standard ]

numberFormatPart

RES
type numberFormatPart = { \"type": numberFormatPartType, value: string, }

numberFormatPartType

RES
type numberFormatPartType = [ | #compact | #currency | #decimal | #exponentInteger | #exponentMinusSign | #exponentSeparator | #fraction | #group | #infinity | #integer | #literal | #minusSign | #nan | #percentSign | #plusSign | #unit | #unknown ]

numberFormatRangePart

RES
type numberFormatRangePart = { \"type": numberFormatPartType, value: string, source: rangeSource, }

options

RES
type options = { compactDisplay?: compactDisplay, numberingSystem?: Intl_Common.numberingSystem, currency?: currency, currencyDisplay?: currencyDisplay, currencySign?: currencySign, localeMatcher?: Intl_Common.localeMatcher, notation?: notation, signDisplay?: signDisplay, style?: style, unit?: unitSystem, unitDisplay?: unitDisplay, useGrouping?: Grouping.t, roundingMode?: rounding, roundingPriority?: roundingPriority, roundingIncrement?: roundingIncrement, trailingZeroDisplay?: trailingZeroDisplay, minimumIntegerDigits?: Intl_Common.oneTo21, minimumFractionDigits?: Intl_Common.zeroTo20, maximumFractionDigits?: Intl_Common.zeroTo20, minimumSignificantDigits?: Intl_Common.oneTo21, maximumSignificantDigits?: Intl_Common.oneTo21, }

rangeSource

RES
type rangeSource = [#endRange | #shared | #startRange]

resolvedOptions

RES
type resolvedOptions = { currency?: currency, currencyDisplay?: currencyDisplay, currencySign?: currencySign, compactDisplay?: compactDisplay, unit: unitSystem, unitDisplay: unitDisplay, roundingMode?: rounding, roundingPriority?: roundingPriority, roundingIncrement?: roundingIncrement, minimumIntegerDigits?: Intl_Common.oneTo21, minimumFractionDigits?: Intl_Common.zeroTo20, maximumFractionDigits?: Intl_Common.zeroTo20, minimumSignificantDigits?: Intl_Common.oneTo21, maximumSignificantDigits?: Intl_Common.oneTo21, locale: string, notation: notation, numberingSystem: Intl_Common.numberingSystem, signDisplay: signDisplay, style: style, useGrouping: Grouping.t, }

resolvedOptions

RES
let resolvedOptions: t => resolvedOptions

resolvedOptions(formatter) returns the actual options being used.

Examples

RES
let formatter = Intl.NumberFormat.make(~locales=["en-US"]) Intl.NumberFormat.resolvedOptions(formatter).locale == "en-US"

rounding

RES
type rounding = [ | #ceil | #expand | #floor | #halfCeil | #halfEven | #halfExpand | #halfFloor | #halfTrunc | #trunc ]

roundingIncrement

RES
type roundingIncrement = [ | #1 | #10 | #100 | #1000 | #2 | #20 | #200 | #2000 | #25 | #250 | #2500 | #5 | #50 | #500 | #5000 ]

roundingPriority

RES
type roundingPriority = [ | #auto | #lessPrecision | #morePrecision ]

signDisplay

RES
type signDisplay = [ | #always | #auto | #exceptZero | #negative | #never ]

style

RES
type style = [#currency | #decimal | #percent | #unit]

supportedLocalesOf

RES
let supportedLocalesOf: ( array<string>, ~options: supportedLocalesOptions=?, ) => array<string>

supportedLocalesOf(locales, ~options) filters locales to those supported for number formatting.

See Intl.NumberFormat.supportedLocalesOf on MDN.

Examples

RES
Intl.NumberFormat.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]

supportedLocalesOptions

RES
type supportedLocalesOptions = { localeMatcher: Intl_Common.localeMatcher, }

t

RES
type t

trailingZeroDisplay

RES
type trailingZeroDisplay = [ | #auto | #lessPrecision | #stripIfInteger ]

unitDisplay

RES
type unitDisplay = [#long | #narrow | #short]

Only used when style is #unit

unitSystem

RES
type unitSystem = string

Defined in https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier Only used when style is #unit