Skip to content

A simple Javascript utility that helps you to display currency properly

License

Notifications You must be signed in to change notification settings

mavenlink/currency-formatter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Currency Formatter

Build Status

A simple Javascript utility that helps you to display currency properly

Reason for Fork

This particular commit on the original repo causes problems for our repo.

From @naganowl, Root cause is a combo of that and using of in CoffeeScript is bad because it turns into an in in Javascript which loops over keys you don't own. We have a lot of CoffeeScript doing this when it should be using in which turns into a basic for loop It's not a problem with the library as much as it's a problem with our problematic CoffeeScript

Once/If the Array.Prototype polyfill is removed, the original repo can be used.

Install

npm install currency-formatter --save

Basic Usage

var currencyFormatter = require('currency-formatter');

currencyFormatter.format(1000000, { code: 'USD' });
// => '$1,000,000.00'

currencyFormatter.format(1000000, { code: 'GBP' });
// => '£1,000,000.00'

currencyFormatter.format(1000000, { code: 'EUR' });
// => '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
// }

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 @'

You could also get a list of all the currencies here using one of the following:

var currencies = require('currency-formatter/currencies');
// OR
var currencyFormatter = require('currency-formatter');
var currencies = currencyFormatter.currencies;

License

MIT

About

A simple Javascript utility that helps you to display currency properly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%