Currency Formatter
Cloned from: https://github.com/smirzaei/currency-formatter
A simple Javascript utility that helps you to display currency properly with additional currency formats
Install
npm install cr-custom-currency-formatter --save
Basic Usage
By specifying the currency code
var currencyFormatter = ; currencyFormatter;// => '$1,000,000.00' currencyFormatter;// => '£1,000,000.00' currencyFormatter;// => '1 000 000,00 €'
Or by specifying the locale
var currencyFormatter = ; currencyFormatter;// => '$1,000,000.00' currencyFormatter;// => '£1,000,000.00' currencyFormatter;// => '£1,000,000.00' currencyFormatter;// => '1.000.000,00 €' currencyFormatter;// => '€1.000.000,00'
You can also get the currency information.
var currencyFormatter = require('currency-formatter'); currencyFormatter.findCurrency('USD');// returns:// {// code: 'USD',// symbol: '$',// thousandsSeparator: ',',// decimalSeparator: '.',// symbolOnLeft: true,// spaceBetweenAmountAndSymbol: false,// decimalDigits: 2// }
Parse the number of a monetary value
currencyFormatter// => 10.5 currencyFormatter// => 1000000 currencyFormatter// => 10.5 currencyFormatter// => 1000000 currencyFormatter// => 1000.99 currencyFormatter// => 10000 currencyFormatter// => 10 currencyFormatter// => 1000
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' // %s is the symbol and %v is the value}); // => '1^000^000*0 @' // Different formatting for positive and negative valuescurrencyFormatter.format(-10, { format: { pos: '%s%v' // %s is the symbol and %v is the value neg: '(%s%v)', zero: '%s%v' }}); // => ($10)
You could also get a list of all the currencies here using one of the following:
var currencies = ;// ORvar currencyFormatter = ;var currencies = currencyFormattercurrencies;
Or the currencies in hashmap shape:
var currencies = ;// Result:// {// "USD": {// "code": "USD",// "symbol": "$",// "thousandsSeparator": ",",// "decimalSeparator": ".",// "symbolOnLeft": true,// "spaceBetweenAmountAndSymbol": false,// "decimalDigits": 2// },// ...more currencies// }