Numbers Formatter
Usage Example
// Import NumbersFormatter constructor class
let NumbersFormatter = require('numbers-formatter');
// Create an instance of NumbersFormatter
// First parameter is the number or string to format
// Second parameter is JSON options object
let formatter = new NumbersFormatter(20000, {locale: 'da-DK'});
// To get the number formatted according to the locale, use `number` property
formatter.number; // 20 000,00
Supported locales
Currently supported locales:
Locale | Thousands separator | Radix point |
---|---|---|
Canadian (en-ca) | empty space ( ) | comma (,) |
Danish (da-dk) | empty space ( ) | comma (,) |
Finnish (fi-fi) | empty space ( ) | comma (,) |
French (fr-fr) | empty space ( ) | comma (,) |
German (de-de) | empty space ( ) | comma (,) |
Italian (it-it) | empty space (.) | comma (,) |
Norwegian(nb-no) | empty space (.) | comma (,) |
Norwegian(nh-no) | empty space (.) | comma (,) |
Spanish (es-es) | empty space (.) | comma (,) |
Swedish (sv-se) | empty space (.) | comma (,) |
GB-English (en-gb) | empty space (,) | comma (.) |
US-English (en-us) | empty space (,) | comma (.) |
Thai (th-th) | empty space (,) | comma (.) |
To add any missing locales, make a pull request to src/locales.js with appropriate options.
TO DO:
- Write down the available options on README i.e. cents, custom separators and radix
- Add ability to use custom separators and radix
- Add various other checkers such as whether number is float, int, etc.
- Add contribution guidelines
- Add license
Resources
- Decimal and Thousands Separators by Oracle
- Table of Language Culture Names by Microsoft