format-number vs accounting vs currency.js vs numeral
JavaScript Number Formatting Libraries
format-numberaccountingcurrency.jsnumeralSimilar 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
format-number84,09251-69 years agoBSD-3-Clause
accounting04,997-14412 years ago-
currency.js03,367-595 years agoMIT
numeral09,715-3499 years agoMIT

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

Currency Formatting

  • 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.

  • 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.

  • 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

  • format-number:

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

  • 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.

  • 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

  • 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.

  • 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.

  • 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

  • format-number:

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

  • 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.

  • 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

  • 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.

  • 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.

  • 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: format-number vs accounting vs currency.js vs numeral

  • 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.

  • 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.

  • 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 format-number

Build Status

format-number

Highly configurable formatter that expects a valid number in 'computer' format and accepts the following as options for formatting

Options

  • negativeType string: 'right','left','brackets','none'; default = 'left' (note only used for setting of default symbols)
  • negativeLeftSymbol string: default = '-' if negativeType is 'left', '(' if negativeType is 'brackets' and '' otherwise
  • negativeRightSymbol string: default = '-' if negativeType is 'right', ')' if negativeType is 'brackets' and '' otherwise
  • negativeLeftOut boolean: whether the left symbol should be outside, ie precede the prefix; default = true
  • negativeRightOut boolean: whether the right symbol should be outside, ie follow the suffix; default = true
  • prefix string: default = ''
  • suffix string: default = ''
  • integerSeparator string: to be used as the thousands separator; default = ','
  • decimalsSeparator string: to be used as the thousanths separator; default = ''
  • decimal string: char to be used as decimal point; default = '.'
  • padLeft number: leading 0s will be added to left of number to make integer part this length; default = -1 /no padding
  • padRight number: trailing 0s will be added; default = -1 /no padding
  • round number: number of decimal places to round to (rounds to nearest integer, mid point rounds away from zero ie 3.55 ~ 3.6 to 1dp, -3.55 ~ -3.6 to 1dp; default = no rounding
  • truncate number: number of decimal places to truncate (3.58 truncates to 3.5 for 1dp, 3 for 0dp); default = no truncating

Override Options

  • noUnits boolean: if true will override and leave out prefix and suffix; default= false
  • noSeparator - boolean: if true will override both integer and decimals separator and leave them out

Usage

var format=require('format-number');
var formattedNumber = format({prefix: '£', suffix: '/item'})(68932, {noSeparator: true});

or

var format=require('format-number');
var myFormat = format({prefix: '£', suffix: '/item'});
var formattedNumber = myFormat(68932, {noSeparator: true});

will both set formattedNumber to '£68932/item'

The override options can be ommitted:

var format=require('format-number');
var formattedNumber = format({prefix: '£', suffix: '/item'})(68932);

returns '£68,932/item'