Number formatter

Every language has its own norms for writing numbers: the decimal separator, digit grouping, the labels for thousands and millions. Formatters apply the norms of the current locale and update the output when the language changes. Use them anywhere a user reads numbers.

In large numbers, digits are grouped in threes, counting from the right. Use the kbqNumber pipe in text and kbqTableNumber in tables. The pipes differ in the threshold at which grouping starts. The numbers below follow the Russian locale; other locales use their own separator and always separate digit groups.

kbqNumber groups digits in numbers from 10 000 up, that is, starting from five digits: 1234, 56 789, 987 654, 1 000 000 000. In running text, a short number reads more naturally without a separator.

kbqTableNumber always separates digit groups: 1 234, 56 789, 987 654, 1 000 000 000. In a table, even columns make it easier to compare values by digit place from top to bottom.

Both pipes accept an optional digitsInfo string that sets the number of integer and fraction digits:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}-{useGrouping}
ParameterDefaultDescription
minIntegerDigits1Minimum number of integer digits
minFractionDigits0Minimum number of fraction digits
maxFractionDigits3Maximum number of fraction digits
useGroupingtrueTurns digit grouping on or off

For example, '4.0-2-false' keeps 4 integer and up to 2 fraction digits and disables grouping.

digitsInfokbqNumberkbqTableNumber
—1,000.1231,000.123
5.5-501,000.1230001,000.12300
4.5-51,000.123001,000.12300
4.0-21,000.121,000.12
4.0-2-false1000.121000.12
4.0-01,0001,000

The kbqRoundNumber pipe displays large numbers in a short form: a thousand as K, a million as M, a billion as B, and so on.

Full numberFormatted value
1,0001.0K
10,00010K
100,000100K
1,000,0001.0M
10,000,00010M
100,000,000100M
1,000,000,0001.0B

By default the pipes use the current application locale. Pass a locale code as the last argument to format a value in the specified locale regardless of the active one.

LocalekbqNumberkbqRoundNumber
ru-RU1 234 567,891,2 М
en-US1,234,567.891.2M
es-LA1 234 567,891,2M
pt-BR1.234.567,891,2 mi
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.