Format a number.
Format a given number using fixed-point notation, with user specified digit
counts and seperators. null
or 'undefined' can be used for optional
arguments to denote that the default value is to be used.
Kind: Exported function
Returns: string
- The numerical value with the choosen formatting.
Param | Type | Default | Description |
---|---|---|---|
value | number |
The numerical value to be formatted. | |
[digits] | number |
2 |
The number of digits to appear after the decimal point; this may be a value between 0 and 20, inclusive. |
[sectionLength] | number |
3 |
Length of integer part sections. |
[sectionDelimiter] | string |
"," |
Integer part section delimiter. |
[decimalDelimiter] | string |
"." |
Decimal delimiter. |
Example
import numberFormat from 'number-format-x';
numberFormat(12345678.9, 3); // "12,345,678.900"
numberFormat(12345678.9, null, null, '.', ','); // "12.345.678,90"
numberFormat(123456.789, 4, 4, ' ', ':'); // "12 3456:7890"
numberFormat(12345678.9, 0, null, '-'); // "12-345-679"