Skip to content
LogoLogo

Input and display of amounts

1,000 can mean one thousand or one. An amount entered as text has no unambiguous meaning without a locale.

Wallets should use the user's preferred locale for both displaying and entering amounts. Default to the device locale and let the user override it in settings whilst getting asset decimals from the asset metadata.

Input


That's 123456 base units

en-USUSD

Read the amount as text using one explicit locale. Accept that locale's digits, separators, and grouping pattern; reject misplaced grouping, unknown separators, and fractions longer than the asset supports. For locales whose grouping separator is whitespace, treating other Unicode whitespace characters as equivalent makes pasted values more reliable. Unicode formatting controls used for bidirectional text can be ignored safely.

An interface should retain an incomplete value while the user is typing, but an invalid value must not reach confirmation or signing.

Display


1,234.56

en-USUSD

Start with integer base units, insert the decimal point using the asset's decimals, then format the exact value using the user's locale. Avoid intermediate floating-point numbers if possible.

Test cases

InputLocaleDecimalsResult
1.000en-US31000
1,000de-DE31000
1.000de-DE31000000
١٬٢٣٤٫٥٦ar-EG2123456
1,23,456.78hi-IN212345678
1,00en-US2Keep typing: incomplete grouping
1,0000en-US2Reject: invalid grouping
1.0001en-US3Reject: too many decimals

See Implementing localized amounts for more details on parsing and formatting.