Numbers
Numbers formatting is done through a pattern-based syntax. With these patterns you can easily define common number formats, similar to date formatting.
Chapter from template v2
Formatting numbers is supported through the built in number function. By default the number formatting option defined either in the global settings or defined in the template settings gets applied. However, it is also possible to pass the required number formatting pattern as an argument ti the number helper function:
{{number numberField}}
{{number numberField format="0.0"}}
--> round to one digit
Introduction
Template Example:
The โmyNumberFieldโ should be a number field from the data (see section Data). The number formatting pattern is optional. Otherwise the default pattern specified in the config will be used.
This is a formatted number:
{{ $number(myNumberField, '+0,0.00') }}
numberFormat: {
pattern: "0,0.X",
locale: "en",
// Optional, can override delimiters from local
delimiters: {
thousands: "โ",
decimal: ".",
},
},
Numeric Locale
The following built in locales are supported:
Code | Language / Region | Main Configuration |
---|---|---|
ar-eg | Arabic / Egypt |
|
ar | Arabic | Same as ar-eg |
de | German |
|
de-ch | German / Switzerland |
|
en-ch | English / Switzerland |
|
en-gb |
|
|
en-in |
|
|
en |
|
|
es |
|
|
fr |
|
|
fr-ch |
|
|
hi |
|
|
id |
|
|
it-ch |
|
|
it |
|
|
ja |
|
|
pt |
|
|
ru |
|
|
zh |
|
|
Numeric patterns
The numeric pattern syntax defines:
Amount of decimal places
Thousands separator (grouping)
Number sign type (+ - and ())
Number sign position
Positive sign visibility
Examples
Number | Pattern | Result | Locale |
---|---|---|---|
10000 | "0,0.0000" | "10,000.0000" | en (English) |
1.23 | "0.0" | "1.2" | en (English) |
10000.23 | "0,0" | "10,000" | en (English) |
1000.2345 | "0,0.X" | "1,000.2345" | en (English) |
1000.2345 | "0,0.X" | "1 000,2345" | fr (French) |
0 | "0.00" | "0,00" | fr (French) |
-10000 | "0,0.0" | "-10.000,0" | es (Spanish) |
10000.1234 | "0.000" | "10000.123" | en (English) |
10000.001 | "0[.]00" | "10000" | en (English) |
10000 | "(0,0.0)" | "10,000.0" | en (English) |
-10000 | "(0,0.0)" | "(10,000.0)" | en (English) |
-12300 | "+0,0.00" | "-12,300.00" | en (English) |
12300 | "+0,0.00" | "+1,2300.00" | ja (Japanese) |
1230 | "0,0+" | "1,230+" | en (English) |
1230 | "0,0-" | "1,230" | en (English) |
0.67 | "0.0####" | "0.67" | en (English) |
0.67 | "0.000##" | "0.670" | en (English) |
3162.63 | "0.0####" | "3162.63" | en (English) |
3162.6338 | "0.0####" | "3162.6338" | en (English) |
0.23 | "000.##" | "000.23" | en (English) |
1234.567 | "0,0.00" | "ูกโูฌูขโูฃโูคโูซูฅโูงโ" | arEG (Arabic) |
undefined | "0,0.00" | "" | en (English) |
null | "0.00" | "" | en (English) |
NaN | "0.0" | "" | en (English) |
Percentages
By adding the % symbol to any of the previous patterns, the value is multiplied by 100 and the % symbol is added in the place indicated.
Number | Pattern | Result | Locale |
---|---|---|---|
0.52 | "0.##%" | "52%" | en (English) |
1 | "0.##%" | "100%" | en (English) |
1 | "0,0.00ย %" | "100.00ย %" | en (English) |
-0.88 | "0ย %" | "-88ย %" | en (English) |
Abbreviated numbers
If an abbreviation is specified in the pattern (a), the shortest abbreviation for your number will be displayed with a locale-specific abbreviation.
Number | Pattern | Result | Locale |
---|---|---|---|
2000000000 | "0.0a" | "2.0B" | en (English) |
1230974 | "0.0a" | "1.2M" | en (English) |
2460 | "0ย a" | "2ย mil" | es (Spanish) |
-104000 | "0ย a" | "-104ย K" | en (English) |
999950 | "0.0a" | "1.0ััั." | ru (Russian) |
999999999 | "0ย a" | "1ย Mio." | de (German) |
Bytes
Adding the 'bd' or 'bb' characters to the pattern will add Byte formatting:
'bd' format bytes in a decimal scale (1000)
'bb' format bytes in a binary scale (1024)
Number | Pattern | Result | Locale |
---|---|---|---|
3500 | "0.00bd" | "3.50KB" | en (English) |
3500 | "0.00bb" | "3.42KiB" | en (English) |
-3500000 | "0.00bb" | "-3.34MiB" | en (English) |
2444222000000 | "0.00bd" | "2.44TB" | en (English) |
2444222000000 | "0.00bb" | "2.22TiB" | en (English) |
Ordinal numbers
Based on the locale. The character 'o' in the mask will enable the ordinal numbers formatting.
Number | Pattern | Result | Locale |
---|---|---|---|
1 | "0o" | "1st" | en (English) |
2 | "0o" | "2nd" | en (English) |
3 | "0o" | "3rd" | en (English) |
4 | "0o" | "4th" | en (English) |
1 | "0o" | "1er" | fr (French) |
12 | "0o" | "12ยบ" | es (Spanish) |
8 | "0o" | "8." | de (German) |