num-format ·
Number pretty printer for currency, percents, and adding thousands separators.
FormatCurrency
Parameters
number
: Number - Value to convertroundToInteger
: Boolean - Defaults totrue
(Optional)locale
: String - Defaults to'en-US'
(Optional)currency
: String - Defaults to'USD'
(Optional)
Examples
// Pretty Print: Currency (w/ Cents - Trailing 0s)>> ; // '$123,456.00' // Pretty Print: Currency (w/ Cents)>> ; // '$123,456.78' // Pretty Print: Currency (Rounded)>> ; // '$9,877' // Pretty Print: Currency (Locale Override - United Kingdom - Integer)>> ; // '£123,457'
FormatNumber
Parameters
number
: Number - Value to convertprecision
: Number - Defaults to2
(Optional)locale
: String - Defaults to'en-US'
(Optional)
Examples
// Pretty Print: Number (2 places)'>> ; // '1,000' // Pretty Print: Number (1 place)'>> ; // '1,234,567.9' // Pretty Print: Number (0 places - Round)'>> ; // '22,333'
FormatPercent
Parameters
number
: Number - Value to convertprecision
: Number - Defaults to2
(Optional)locale
: String - Defaults to 'en-US' (Optional)
Examples
// Pretty Print: Percentage (2 places)'>> ; // '85.22%' // Pretty Print: Percentage (Trailing 0)'>> ; // '13.50%' // Pretty Print: Percentage (1 place)'>> ; // '73.4%' // Pretty Print: Percentage (0 places - Round Up)'>> ; // '56%' // Pretty Print: Percentage (0 places - Round Down)>> ; // '33%'
Locale Support:
In the current version of num-format it should be assumed that only en-US
formatting is supported as Node 8.x has limited locale support.