Format and unformat numbers with SI prefixes
npm install @nickfaughey/format-si-prefixformatSI()javascript
import {formatSI} from 'format-si-prefix';
const string = formatSI(number, options); // optional options object
`
Options:
- space: (default false) adds a space between the number and prefix (ex. 1.2 k)
- sign: (default false) prepends a plus sign if the number is positive (ex. +1.2k)
- suffix: appends a string to the formatted number (ex. formatSI(1200, {suffix: 'Wh'}) => 1.2kWh)
| in | out |
| ------------- | -------:|
| ... | ... |
| 0.000111111 | 111µ |
| 0.00111 | 1.11m |
| 0.0111 | 11.1m |
| 0.111 | 111m |
| 1 | 1 |
| 11 | 11 |
| 111 | 111 |
| 1111 | 1.11k |
| 11111 | 11.1k |
| 111111 | 111k |
| 1111111 | 1.11M |
| ... | ... |
unformatSI()
`javascript
import {unformatSI} from 'format-si-prefix';
const number = unformatSI(string);
``