Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
currency-formatter
Advanced tools
A simple Javascript utility that helps you to display currency properly
A simple Javascript utility that helps you to display currency properly
npm install currency-formatter --save
By specifying the currency code
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 €'
Or by specifying the locale
var currencyFormatter = require('currency-formatter');
currencyFormatter.format(1000000, { locale: 'en-US' });
// => '$1,000,000.00'
currencyFormatter.format(1000000, { locale: 'en-GB' });
// => '£1,000,000.00'
currencyFormatter.format(1000000, { locale: 'GB' });
// => '£1,000,000.00'
currencyFormatter.format(1000000, { locale: 'de-DE' });
// => '1.000.000,00 €'
currencyFormatter.format(1000000, { locale: 'nl-NL' });
// => '€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.unformat('$10.5', { code: 'USD' })
// => 10.5
currencyFormatter.unformat('$1,000,000', { code: 'USD' })
// => 1000000
currencyFormatter.unformat('10,5 €', { code: 'EUR' })
// => 10.5
currencyFormatter.unformat('1 000 000,00 €', { code: 'EUR' })
// => 1000000
currencyFormatter.unformat('1.000,99', { locale: 'de-DE' })
// => 1000.99
currencyFormatter.unformat('10\'000 CHF', { code: 'CHF' })
// => 10000
currencyFormatter.unformat('10.00 CHF', { code: 'CHF' })
// => 10
currencyFormatter.unformat('10,00 CHF', { code: 'CHF' })
// => 1000
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 values
currencyFormatter.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 = require('currency-formatter/currencies');
// OR
var currencyFormatter = require('currency-formatter');
var currencies = currencyFormatter.currencies;
Or the currencies in hashmap shape:
var currencies = require('currency-formatter/currencies.json');
// Result:
// {
// "USD": {
// "code": "USD",
// "symbol": "$",
// "thousandsSeparator": ",",
// "decimalSeparator": ".",
// "symbolOnLeft": true,
// "spaceBetweenAmountAndSymbol": false,
// "decimalDigits": 2
// },
// ...more currencies
// }
FAQs
A simple Javascript utility that helps you to display currency properly
The npm package currency-formatter receives a total of 44,407 weekly downloads. As such, currency-formatter popularity was classified as popular.
We found that currency-formatter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.