currency-codes vs currency.js vs dinero.js vs numeral
JavaScript Currency Libraries
currency-codescurrency.jsdinero.jsnumeralSimilar Packages:

JavaScript Currency Libraries

These libraries provide various functionalities for handling currency values in JavaScript applications. They facilitate tasks such as currency formatting, arithmetic operations, and conversion between different currencies. Each library has its unique features, making them suitable for different use cases in web development, especially in financial applications or e-commerce platforms.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
currency-codes016487 kB24a year agoMIT
currency.js03,359-585 years agoMIT
dinero.js06,539-34 years agoMIT
numeral09,728-3499 years agoMIT

Feature Comparison: currency-codes vs currency.js vs dinero.js vs numeral

Currency Formatting

  • currency-codes:

    currency-codes does not provide formatting capabilities but offers a reliable list of currency codes and their respective symbols, which can be used in conjunction with other libraries for formatting purposes.

  • currency.js:

    currency.js provides built-in methods for formatting currency values, allowing you to easily display numbers as currency strings with customizable options for decimal places and currency symbols.

  • dinero.js:

    dinero.js excels in currency formatting, allowing you to format money objects into human-readable strings while ensuring the correct currency symbol and decimal precision are applied based on locale settings.

  • numeral:

    numeral offers extensive formatting options, including currency formatting. You can format numbers as currency strings with various configurations, making it suitable for applications needing diverse number formats.

Arithmetic Operations

  • currency-codes:

    This library does not perform arithmetic operations; it is solely focused on providing currency codes and symbols.

  • currency.js:

    currency.js supports basic arithmetic operations such as addition, subtraction, multiplication, and division directly on currency values, making it easy to calculate totals and differences.

  • dinero.js:

    dinero.js provides robust arithmetic capabilities while maintaining precision, allowing you to perform complex calculations with money objects, including addition, subtraction, multiplication, and division, all while handling rounding issues effectively.

  • numeral:

    numeral allows basic arithmetic operations but is primarily focused on formatting. It is not designed for precise financial calculations, so it may not be suitable for applications requiring strict monetary accuracy.

Precision Handling

  • currency-codes:

    This library does not deal with precision as it focuses on currency identification rather than calculations.

  • currency.js:

    currency.js handles precision by allowing you to define the number of decimal places for currency values, ensuring that calculations remain accurate and formatted correctly for display.

  • dinero.js:

    dinero.js is designed with precision in mind, utilizing integer representation for currency values to avoid floating-point errors, which is crucial for financial applications where accuracy is paramount.

  • numeral:

    numeral does not specifically address precision in financial calculations, making it less suitable for applications where monetary accuracy is critical.

Localization Support

  • currency-codes:

    currency-codes supports localization by providing currency codes and symbols based on country, making it easier to adapt to different regional requirements.

  • currency.js:

    currency.js has limited localization support, primarily focusing on formatting based on the specified currency type but lacks extensive locale management features.

  • dinero.js:

    dinero.js offers strong localization support, allowing you to format currency values according to different locales and currencies, making it ideal for international applications.

  • numeral:

    numeral provides basic localization features for number formatting, including currency, but may not cover all aspects of currency localization as effectively as other libraries.

Use Cases

  • currency-codes:

    Best used in applications that require a reference for currency codes and symbols, such as e-commerce platforms needing to display prices in various currencies without calculations.

  • currency.js:

    Ideal for simple applications that require basic currency formatting and arithmetic, such as shopping carts or invoice generators where straightforward calculations are needed.

  • dinero.js:

    Perfect for complex financial applications that require accurate currency calculations and formatting, such as accounting software or payment processing systems that handle multiple currencies.

  • numeral:

    Suitable for applications needing flexible number formatting beyond currency, such as dashboards or reporting tools that display various numerical data types.

How to Choose: currency-codes vs currency.js vs dinero.js vs numeral

  • currency-codes:

    Choose currency-codes if you need a comprehensive list of currency codes and their corresponding countries. This package is ideal for applications that require accurate currency identification and localization without complex calculations.

  • currency.js:

    Select currency.js for simple and effective currency formatting and arithmetic. It is great for projects that need straightforward currency manipulation, such as displaying prices or calculating totals without the overhead of complex features.

  • dinero.js:

    Opt for dinero.js when you require a robust solution for handling money in JavaScript, including precise arithmetic and currency formatting. This library is suitable for applications that need to perform complex financial calculations while ensuring accuracy and compliance with currency standards.

  • numeral:

    Use numeral if you need a versatile library for number formatting, including currency formatting. This package is a good choice for applications that require a wide range of formatting options beyond just currency, such as percentages and decimals.

README for currency-codes

currency-codes

A node.js module to list and work on currency codes based on the ISO 4217 standard.

npm install currency-codes

code('EUR')

var cc = require('currency-codes');
console.log(cc.code('EUR'));

/*
{
	code: 'EUR',
	number: 978,
	digits: 2,
	currency: 'Euro',
	countries: [
		'andorra', 'austria', 'belgium', 'cyprus', 'estonia', 'finland',
		'france', 'germany', 'greece', 'ireland', 'italy', 'kosovo',
		'luxembourg', 'malta', 'monaco', 'montenegro', 'netherlands',
		'portugal', 'san marino', 'slovakia', 'slovenia', 'spain',
		'vatican city' ]
}
*/

number(967)

var cc = require('currency-codes');
console.log(cc.number(967));

/*
{
	code: 'ZMW',
	number: 967,
	digits: 2,
	currency: 'Zambian kwacha',
	countries: [ 'zambia' ] }
*/

country('colombia')

var cc = require('currency-codes');
console.log(cc.country('colombia'));

/*
[
	{
		code: 'COP',
		number: 170,
		digits: 2,
		currency: 'Colombian peso',
		countries: [ 'colombia' ]
	}, {
		code: 'COU',
		number: 970,
		digits: 2,
		currency: 'Unidad de Valor Real',
		countries: [ 'colombia' ]
	}
]
*/

codes()

var cc = require('currency-codes');
console.log(cc.codes());

/*
[
	'AED',
	'AFN',
	...
	'ZAR',
	'ZMW'
]
*/

numbers()

var cc = require('currency-codes');
console.log(cc.numbers());

/*
[
	'784',
	'971',
	...
	'710',
	'967'
]
*/

countries()

var cc = require('currency-codes');
console.log(cc.countries());

/*
[
	'united arab emirates',
	'afghanistan',
	...
]
*/

data

var data = require('currency-codes/data');
console.log(data);

/*
[{
	code: 'AED',
	number: '784',
	digits: 2,
	currency: 'United Arab Emirates dirham',
	countries: ['united arab emirates']
}, {
	code: 'AFN',
	number: '971',
	digits: 2,
	currency: 'Afghan afghani',
	countries: ['afghanistan']
}, {
	...
*/

publishDate

var cc = require('currency-codes');

console.log(cc.publishDate);

/*
2024-06-25
*/

Updating the data

Fetch the latest copy of ISO-4217 from the maintainer and update this library's currency data file.

$ npm run iso

> currency-codes@2.1.0 iso
> npm run iso:fetch-xml && npm run iso:ingest-xml


> currency-codes@2.1.0 iso:fetch-xml
> node scripts/fetch-iso-4217-xml.js

Downloaded https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xml to iso-4217-list-one.xml

> currency-codes@2.1.0 iso:ingest-xml
> node scripts/ingest-iso-4217-xml.js

Ingested iso-4217-list-one.xml into data.js
Wrote publish date to iso-4217-publish-date.js

Note: You may have to manually tweak the capitalization of some country's names.

License

MIT