Skip to content
IC Reactor

FormatTokenAmountOptions

Defined in: core/src/utils/token-amount.ts:96

Options for formatTokenAmount.

optional maxFractionDigits?: number

Defined in: core/src/utils/token-amount.ts:102

The most fraction digits to show. Digits past it are dropped as roundingMode says. Defaults to the token’s decimals, which shows the amount exactly, or to minFractionDigits when that is more.


optional minFractionDigits?: number

Defined in: core/src/utils/token-amount.ts:107

The fewest fraction digits to show, padded with zeros: 2 shows one ICP as "1.00". Defaults to 0.


optional trimTrailingZeros?: boolean

Defined in: core/src/utils/token-amount.ts:113

Drop zeros at the end of the fraction, down to minFractionDigits. Defaults to true, so one ICP shows as "1". With false the fraction is padded to maxFractionDigits: "1.00000000".


optional roundingMode?: "trunc" | "halfExpand"

Defined in: core/src/utils/token-amount.ts:120

How digits past maxFractionDigits are dropped. "trunc" (the default) cuts them, so a balance of 0.99999999 shown to two digits is "0.99", never more than is held. "halfExpand" rounds half away from zero, as Intl.NumberFormat does: "1".


optional locale?: string | readonly string[]

Defined in: core/src/utils/token-amount.ts:127

A BCP 47 locale, such as "de-DE", whose decimal separator, grouping and digits to use, through Intl.NumberFormat. Without one the text is plain: -, the digits 0-9 and ., the form parseTokenAmount reads back, and the same on the server and in every browser.


optional useGrouping?: boolean

Defined in: core/src/utils/token-amount.ts:133

Group the whole part into thousands. Without a locale this writes , every three digits and defaults to false; with one it follows the locale, as Intl.NumberFormat does.