currency.js vs accounting vs format-number vs intl vs numbro vs numeral
JavaScript Libraries for Number Formatting and Currency Management
currency.jsaccountingformat-numberintlnumbronumeralSimilar Packages:

JavaScript Libraries for Number Formatting and Currency Management

These libraries provide various functionalities for formatting numbers, currencies, and handling internationalization in JavaScript applications. They simplify the process of displaying numbers and currencies in a user-friendly way, ensuring that developers can easily manage localization and formatting according to different regional standards. Each library has its unique features and use cases, catering to different needs in web development.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
currency.js499,9623,364-585 years agoMIT
accounting278,1915,000-14412 years ago-
format-number51,88051-69 years agoBSD-3-Clause
intl01,693-799 years agoMIT
numbro01,1401.27 MB2702 years agoMIT
numeral09,726-3499 years agoMIT

Feature Comparison: currency.js vs accounting vs format-number vs intl vs numbro vs numeral

Core Functionality

  • currency.js:

    currency.js specializes in currency manipulation, offering features like currency conversion, formatting, and arithmetic operations with precision. It supports multiple currencies and is tailored for financial applications.

  • accounting:

    accounting.js focuses on financial calculations and currency formatting, providing functions for currency formatting, number formatting, and basic arithmetic operations. It is designed to handle monetary values effectively.

  • format-number:

    format-number provides a straightforward approach to number formatting, allowing developers to format numbers with specified decimal places and thousands separators without complex configurations.

  • intl:

    intl offers a comprehensive set of internationalization features, including number formatting, date formatting, and message formatting, making it suitable for applications that require localization across different cultures.

  • numbro:

    numbro provides extensive formatting options for numbers, including custom formats and localization capabilities, allowing developers to format numbers according to specific regional standards.

  • numeral:

    numeral.js offers powerful number formatting capabilities, including currency, percentages, and custom formats, making it versatile for various applications.

Localization Support

  • currency.js:

    currency.js supports multiple currencies and allows for easy conversion between them, making it suitable for applications with international financial transactions.

  • accounting:

    accounting.js has limited localization support, primarily focusing on US-style formatting. It may require additional handling for internationalization needs.

  • format-number:

    format-number provides basic localization options but may not cover all international formatting needs, making it less suitable for global applications.

  • intl:

    intl excels in localization, providing robust support for different locales and formats, making it ideal for applications targeting a diverse audience.

  • numbro:

    numbro offers good localization support, allowing developers to format numbers based on specific locales, enhancing user experience in different regions.

  • numeral:

    numeral.js provides basic localization features but may not be as comprehensive as other libraries for internationalization.

Ease of Use

  • currency.js:

    currency.js is straightforward to use, with a simple API that allows developers to perform currency operations easily, making it accessible for beginners.

  • accounting:

    accounting.js is user-friendly and easy to integrate, making it suitable for developers who need quick solutions for financial formatting without complex setups.

  • format-number:

    format-number is designed for simplicity, making it easy to implement for basic number formatting tasks without additional overhead.

  • intl:

    intl may have a steeper learning curve due to its comprehensive features, but it offers extensive documentation to assist developers in utilizing its capabilities effectively.

  • numbro:

    numbro is relatively easy to use, with a clear API for formatting numbers, making it approachable for developers of all skill levels.

  • numeral:

    numeral.js is user-friendly and provides a simple API for formatting numbers, making it easy to adopt for various applications.

Performance

  • currency.js:

    currency.js is optimized for performance, especially in applications that require frequent currency calculations and conversions.

  • accounting:

    accounting.js is lightweight and performs well for basic formatting tasks, making it suitable for applications where performance is a concern.

  • format-number:

    format-number is efficient for simple number formatting tasks, ensuring minimal overhead in performance-sensitive applications.

  • intl:

    intl may have performance implications due to its comprehensive features, but it is designed to handle a wide range of formatting efficiently.

  • numbro:

    numbro is designed for performance, providing fast formatting options for numbers, making it suitable for applications with high formatting demands.

  • numeral:

    numeral.js performs well for various formatting tasks, but performance may vary depending on the complexity of the formatting required.

Community and Support

  • currency.js:

    currency.js has a growing community and offers good documentation, making it easier for developers to find support and resources.

  • accounting:

    accounting.js has a smaller community but provides sufficient documentation for basic usage, making it easy to get started.

  • format-number:

    format-number has limited community support, but its simplicity means that most developers can quickly understand and implement it without extensive help.

  • intl:

    intl has a large community and extensive documentation, providing ample resources for developers looking to implement internationalization in their applications.

  • numbro:

    numbro has a moderate community and offers decent documentation, making it relatively easy to find help when needed.

  • numeral:

    numeral.js has a strong community and good documentation, providing developers with resources and support for various use cases.

How to Choose: currency.js vs accounting vs format-number vs intl vs numbro vs numeral

  • currency.js:

    Select currency.js if you require a robust solution for currency manipulation, including support for various currencies, precision handling, and built-in methods for common currency operations. It is ideal for applications that need to handle multiple currencies effectively.

  • accounting:

    Choose accounting.js if you need a lightweight library specifically for accounting purposes, such as formatting currency and performing basic arithmetic operations with numbers. It is straightforward and easy to use for financial applications.

  • format-number:

    Opt for format-number if you need a simple and flexible solution for number formatting without additional dependencies. It is useful for straightforward number formatting tasks and works well in smaller projects or where minimalism is preferred.

  • intl:

    Use the intl library if you need comprehensive internationalization support, including number formatting, date and time formatting, and message formatting. It is especially useful for applications targeting a global audience with diverse localization needs.

  • numbro:

    Choose numbro if you want a library that offers extensive formatting options for numbers, including custom formats and localization. It is beneficial for applications that require detailed control over number presentation.

  • numeral:

    Select numeral.js for a versatile library that provides powerful number formatting capabilities, including currency, percentages, and custom formats. It is suitable for applications that need a wide range of formatting options.

README for currency.js

currency.js logo

currency.js

Build Status Coverage Status npm gzip size

currency.js is a lightweight ~1kb javascript library for working with currency values. It was built to work around floating point issues in javascript. This talk by Bartek Szopka explains in detail why javascript has floating point issues.

currency.js works with values as integers behind the scenes, resolving some of the most basic precision problems.

2.51 + .01;                   // 2.5199999999999996
currency(2.51).add(.01);      // 2.52

2.52 - .01;                   // 2.5100000000000002
currency(2.52).subtract(.01); // 2.51

This should work for most reasonable values of currencies. As long as your currency values are less than 253 (in cents) or 90,071,992,547,409.91 you should be okay.

Features

  • 0 dependencies!
  • Immutable
  • Flexible formatting options
  • Handles any type of currency input, strings, numbers, or another currency instance

Installation

With npm:

npm install --save currency.js

With yarn:

yarn add currency.js

Via cdn:

<script src="https://unpkg.com/currency.js@~2.0.0/dist/currency.min.js"></script>

Need the latest cutting edge? All commits on master are tagged with next on npm:

npm install --save currency.js@next

Usage

Currency will accept numbers, strings, or the currency object itself as values.

currency(123);      // 123.00
currency(1.23);     // 1.23
currency("1.23")    // 1.23
currency("$12.30")  // 12.30

var value = currency("123.45");
currency(value);    // 123.45

Currency accepts decimal values (i.e. 1.23) with a default precision of 2, but can accept a minor currency unit (e.g. cents in a dollar). This will respect the precision option when parsing.

currency(123, { fromCents: true });               // 1.23
currency('123', { fromCents: true });             // 1.23
currency(123, { fromCents: true, precision: 0 }); // 123
currency(123, { fromCents: true, precision: 3 }); // 0.123

There's various arithmetic methods that help take the guesswork out of trying to resolve floating point problems.

currency(123.50).add(0.23);       // 123.73
currency(5.00).subtract(0.50);    // 4.50
currency(45.25).multiply(3);      // 135.75
currency(1.12).distribute(5);     // [0.23, 0.23, 0.22, 0.22, 0.22]

There's even a built in formatter that will automatically place comma delimiters in the right place.

currency("2,573,693.75").add("100,275.50").format();  // "$2,673,969.25"
currency("1,237.72").subtract(300).format();          // "$937.72"

You can also change the format, localizing the decimal and/or delimiter to your locale.

var euro = value => currency(value, { symbol: "€", separator: ".", decimal: "," });
euro("2.573.693,75").add("100.275,50").format();  // "€2.673.969,25"
euro("1.237,72").subtract(300).format();          // "€937,72"

Options

currency.js comes with its own set of default options conforming to USD. You can customize these according to your locale.

symbol default: $
Currency symbol included when calling currency.format().

separator default: ,
Separator dividing the number groups when calling currency.format().

decimal default: .
Decimal used when calling currency.format().

precision default: 2
Number of decimal places to store as cents.

pattern default: !#
Allows you to customize the format pattern using ! as replacement for the currency symbol and # as replacement for the currency amount.

negativePattern default: -!#
Allows you to customize the negative format pattern using ! as replacement for the currency symbol and # as replacement for the currency amount.

format default null Allows you to customize the format of the currency when calling currency.format(). format passes in the currency object as well as the options object to the function and expects a string to be returned. Use this when the provided formatting options do not meet your needs.

errorOnInvalid default: false
If an invalid value such as null or undefined is passed in, will throw an error.

increment default: null
When implementing a currency that implements rounding, setting the increment value will allow you to set the closest increment to round the display value to. currency(1.48, { increment: .05 }); // => 1.50

useVedic default: false
Formats number groupings using the Indian Numbering System, i.e. 10,00,000.00

fromCents default: false
Parse the amount value as a minor currency unit (e.g. cents in a dollar) instead of dollars.

View more examples and full documentation at https://currency.js.org.

Internationalization Examples

currency(1.23, { separator: " ", decimal: ",", symbol: "€" });

If you need to work with multiple currency values, the easiest way is to setup factory functions with your required currency settings.

const USD = value => currency(value, { symbol: "$", precision: 2 });
const JPY = value => currency(value, { symbol: "¥", precision: 0 });
const GAS = value => currency(value, { precision: 3 });

USD(1234.56).format(); // "$1,234.56"
JPY(1234.56).format(); // "¥1,235"
GAS(1234.56).format(); // "$1,234.560"

Add-ons

Other Libraries

Maybe currency.js isn't the right fit for your needs. Check out some of these other fine libraries:

License

MIT