Currency Formatter
A simple Javascript utility that helps you to display currency properly
Install
npm install currency-formatter --save
Basic Usage
By specifying the currency code
var currencyFormatter = require('currency-formatter');
currencyFormatter.format(1000000, { code: 'USD' });
currencyFormatter.format(1000000, { code: 'GBP' });
currencyFormatter.format(1000000, { code: 'EUR' });
Or by specifying the locale
var currencyFormatter = require('currency-formatter');
currencyFormatter.format(1000000, { locale: 'en-US' });
currencyFormatter.format(1000000, { locale: 'en-GB' });
currencyFormatter.format(1000000, { locale: 'GB' });
currencyFormatter.format(1000000, { locale: 'de-DE' });
currencyFormatter.format(1000000, { locale: 'nl-NL' });
You can also get the currency information.
var currencyFormatter = require('currency-formatter');
currencyFormatter.findCurrency('USD');
Advanced Usage
Currency Formatter uses accounting library under the hood, and you can use its options to override the default behavior.
var currencyFormatter = require('currency-formatter');
currencyFormatter.format(1000000, {
symbol: '@',
decimal: '*',
thousand: '^',
precision: 1,
format: '%v %s'
});
currencyFormatter.format(-10, {
format: {
pos: '%s%v'
neg: '(%s%v)',
zero: '%s%v'
}
});
You could also get a list of all the currencies here using one of the following:
var currencies = require('currency-formatter/currencies');
var currencyFormatter = require('currency-formatter');
var currencies = currencyFormatter.currencies;
Or the currencies in hashmap shape:
var currencies = require('currency-formatter/currencies.json');
License
MIT