This article goes over formatting numbers using the toFixed
, commaSeparate
, roundNum
and numberConvert
functions.
Number Formatting Functions
|
Fix a number to specific number of decimal places |
|
$1 → $1.00 |
|
Round a number to specific decimal places |
|
$15.34928 → $15.35 |
|
Separate number with Commas |
|
10000 → 10,000 |
|
Convert integer into text |
|
1000 → one thousand |
|
Convert integer into ordinal text |
|
123 → one hundred twenty third |
Currently numberConvert
will only work for integers. They will not fully convert numbers with decimals into text but will just print the integer part of the number. (e.g. 101.23 → one hundred and one)
You can customize numbers converted to text with numberConvert
by stacking text formatting functions. (e.g. {numShares | numberConvert | upper}
: 1000 → ONE THOUSAND)
You can learn more about text formatting here: upper, lower, firstCase
Stacking Number Formatting Functions
The order to stack these functions are:
-
toFixed
/roundNum
-
commaSeparate
/numberConvert