NumberFormat

compactDisplay

RESCRIPT
type compactDisplay = [#long | #short]

Used only when notation is #compact

currency

RESCRIPT
type currency = string

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

currencyDisplay

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

currencySign

RESCRIPT
type currencySign = [#accounting | #standard]

format

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

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

Examples

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

formatBigInt

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

formatBigInt(formatter, value) formats bigint values.

formatBigIntRange

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

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

Examples

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

formatBigIntRangeToParts

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

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

Examples

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

formatBigIntToParts

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

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

Examples

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

formatInt

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

formatInt(formatter, value) formats integer values.

Examples

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

formatIntRange

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

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

Examples

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

formatIntRangeToParts

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

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

Examples

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

formatIntToParts

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

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

Examples

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

formatRange

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

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

Examples

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

formatRangeToParts

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

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

Examples

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

formatString

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

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

Examples

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

formatStringToParts

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

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

Examples

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

formatToParts

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

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

Examples

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

ignore

RESCRIPT
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

RESCRIPT
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

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

notation

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

numberFormatPart

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

numberFormatPartType

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

numberFormatRangePart

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

options

RESCRIPT
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

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

resolvedOptions

RESCRIPT
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

RESCRIPT
let resolvedOptions: t => resolvedOptions

resolvedOptions(formatter) returns the actual options being used.

Examples

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

rounding

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

roundingIncrement

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

roundingPriority

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

signDisplay

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

style

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

supportedLocalesOf

RESCRIPT
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

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

supportedLocalesOptions

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

t

RESCRIPT
type t

trailingZeroDisplay

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

unitDisplay

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

Only used when style is #unit

unitSystem

RESCRIPT
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