accounting vs currency.js vs format-number vs numeral
JavaScript Number Formatting Libraries
accountingcurrency.jsformat-numbernumeralSimilar Packages:

JavaScript Number Formatting Libraries

These libraries provide developers with tools to format numbers, currencies, and percentages in a consistent and user-friendly manner. They simplify the process of displaying numerical values in various formats, catering to different localization needs and ensuring that applications present data clearly and accurately. Each library has its unique features, making them suitable for different scenarios in web development.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
accounting04,998-13812 years ago-
currency.js03,361-585 years agoMIT
format-number051-69 years agoBSD-3-Clause
numeral09,725-3499 years agoMIT

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

Currency Formatting

  • accounting:

    Accounting.js provides straightforward currency formatting capabilities, allowing you to easily format numbers as currency with customizable symbols and decimal places. It is particularly useful for displaying financial data in a user-friendly manner.

  • currency.js:

    currency.js excels in currency formatting, offering built-in support for multiple currencies and precise formatting options. It allows for easy conversion between currencies and ensures that financial calculations are accurate and reliable.

  • format-number:

    format-number offers basic currency formatting but is more focused on general number formatting. It allows for some customization but lacks the extensive currency-specific features found in other libraries.

  • numeral:

    Numeral.js provides robust currency formatting options with support for custom currency symbols and formatting rules. It allows for detailed control over how currency values are displayed.

Precision Handling

  • accounting:

    Accounting.js handles precision well for basic operations, but it may not be suitable for complex financial calculations requiring high precision due to its reliance on JavaScript's native number handling.

  • currency.js:

    currency.js uses fixed-point arithmetic to ensure high precision in financial calculations, making it ideal for applications that require accurate monetary computations without floating-point errors.

  • format-number:

    format-number does not focus heavily on precision handling and is more suited for general number formatting rather than financial calculations.

  • numeral:

    Numeral.js provides good precision handling for formatting purposes, but it does not perform calculations, so it relies on the underlying JavaScript number handling.

Localization Support

  • accounting:

    Accounting.js has limited localization support, primarily focusing on currency symbols and decimal separators, which may require additional customization for full localization.

  • currency.js:

    currency.js supports multiple currencies and allows for easy localization of currency formats, making it suitable for international applications that require accurate currency representation.

  • format-number:

    format-number offers some localization features, allowing for different number formats based on locale, but it may not cover all localization needs comprehensively.

  • numeral:

    Numeral.js has extensive localization support, allowing developers to define custom formats and localization rules, making it highly adaptable for global applications.

Ease of Use

  • accounting:

    Accounting.js is straightforward and easy to use, with a simple API that allows developers to quickly format numbers and currencies without a steep learning curve.

  • currency.js:

    currency.js is user-friendly and designed for developers who need precise currency handling, but it may require a bit more understanding of its fixed-point arithmetic approach.

  • format-number:

    format-number is easy to use for basic formatting needs, but its flexibility may require some learning to fully leverage its capabilities.

  • numeral:

    Numeral.js is relatively easy to use, with a clear API and extensive documentation, making it accessible for developers looking for a comprehensive formatting solution.

Performance

  • accounting:

    Accounting.js is lightweight and performs well for basic formatting tasks, making it suitable for applications where performance is a priority and complex calculations are not required.

  • currency.js:

    currency.js is optimized for performance in financial calculations, ensuring that operations are efficient and accurate, especially when handling large datasets.

  • format-number:

    format-number performs adequately for general number formatting but may not be as optimized for performance as other libraries when dealing with extensive formatting scenarios.

  • numeral:

    Numeral.js is designed for performance and can handle complex formatting scenarios efficiently, making it a good choice for applications that require high-performance number formatting.

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

  • accounting:

    Choose Accounting.js if you need a lightweight library focused on formatting and manipulating currency values. It provides simple methods for formatting numbers and currencies, making it ideal for applications that require straightforward financial calculations without heavy dependencies.

  • currency.js:

    Select currency.js for its robust handling of currency values, including support for multiple currencies and precise calculations. It's particularly useful for applications that require accurate financial computations and want to avoid floating-point errors, as it uses a fixed-point arithmetic approach.

  • format-number:

    Opt for format-number if you need a versatile library that offers extensive formatting options for numbers, including support for percentages and scientific notation. It is suitable for applications that require a high degree of customization in number formatting.

  • numeral:

    Use Numeral.js when you need a comprehensive library that supports a wide range of formatting options, including currency, percentages, and custom formats. It is ideal for applications that require complex formatting scenarios and want to maintain a clean and readable codebase.

README for accounting

accounting.js is a tiny JavaScript library for number, money and currency parsing/formatting. It's lightweight, fully localisable, has no dependencies, and works great client-side or server-side. Use standalone or as a nodeJS/npm and AMD/requireJS module.

Visit the plugin homepage for demos and documentation: http://openexchangerates.github.io/accounting.js/

Please checkout or download the latest stable tag before using in production. Bug reports and pull requests are welcome.

Maintained by Open Exchange Rates and originally by @josscrowcroft and other contributors.


Works great with:

  • money.js - a tiny (1kb) standalone JavaScript currency conversion library, for web & nodeJS
  • Open Exchange Rates - the free currency conversion data API

Changelog

v0.4.1 - Alias accounting.formatNumber() as accounting.format()

v0.4 - Transferred repository to Open Exchange Rates for ongoing maintenance

v0.3.2 - Fixed package.json dependencies (should be empty object)

v0.3.0

  • Rewrote library structure similar to underscore.js for use as a nodeJS/npm and AMD module. Use npm install accounting and then var accounting = require("accounting"); in your nodeJS scripts.
  • Also works with requireJS or any AMD module loader.
  • unformat now only attempts to parse the number if it's not already a valid number.
  • acounting.unformat now also aliased as acounting.parse
  • Fixed an IE bug in the defaults method

v0.2.2 - Fixed same issue as #Num: #24 in formatNumber; switch to Google Closure Compiler for minified version.

v0.2.1 - Fixed issue #Num: #24 (locally-defined settings object was being modified by formatMoney)

v0.2

  • Rewrote formatting system for formatMoney and formatColumn for better control of string output
  • Now supports separate formats for negative and zero values (optionally) via accounting.settings.currency.format
  • Internal improvements and helper methods

v0.1.4

  • formatMoney recursively formats arrays
  • Added Jasmine test suite (thanks to millermedeiros) and QUnit functionality/speed tests

v0.1.3

  • Added configurable settings object for default formatting parameters.
  • Added format parameter to control symbol and value position (default "%s%v", or [symbol][value])
  • Methods consistently accept object as 2nd parameter, matching/overriding the library defaults

v0.1.2

  • formatColumn works recursively on nested arrays (e.g. accounting.formatColumn( [[1,12,123,1234], [1234,123,12,1]] ), returns matching array with inner columns lined up)
  • Fix rounding in formatNumber

v0.1.1

  • Added toFixed method (accounting.toFixed(value, precision)), which treats floats more like decimals for more accurate currency rounding
  • Minified version preserves semicolons
  • Fixed NaN errors when no value in unformat

v0.1 - First version