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
Package
Downloads
Stars
Size
Issues
Publish
License
format-number
84,092
51
-
6
9 years ago
BSD-3-Clause
accounting
0
4,997
-
144
12 years ago
-
currency.js
0
3,367
-
59
5 years ago
MIT
numeral
0
9,715
-
349
9 years ago
MIT
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.
Popular Comparisons
Similar Npm Packages to format-number
format-number is a lightweight JavaScript library designed to format numbers in a variety of ways. It provides an easy-to-use API for formatting numbers as currency, percentages, or general numeric values, making it a valuable tool for developers who need to present numerical data in a user-friendly manner. While format-number is a solid choice for number formatting, there are several alternatives in the JavaScript ecosystem that offer similar functionalities. Here are a few noteworthy options:
accounting is a comprehensive library for number formatting and currency manipulation. It provides a wide range of features, including formatting numbers, currencies, and percentages, as well as performing basic arithmetic operations. accounting is particularly useful for applications that require extensive financial calculations and formatting, making it a popular choice among developers working with financial data.
currency.js is a library specifically designed for handling currency values in JavaScript. It provides a simple API for creating, manipulating, and formatting currency values, ensuring that developers can easily work with monetary amounts without worrying about precision issues. currency.js is an excellent choice for applications that require accurate currency calculations and formatting, such as e-commerce platforms or financial applications.
numeral is a library that focuses on formatting and manipulating numbers in a variety of ways. It supports a wide range of formatting options, including currency, percentages, and custom formats. numeral is particularly useful for applications that need to display numbers in a specific format, making it a versatile choice for developers looking to enhance the presentation of numerical data.
accounting is a JavaScript library designed for number formatting and currency manipulation. It provides a simple and intuitive API for formatting numbers, currencies, and percentages, making it a popular choice for developers who need to handle financial data in their applications. While accounting.js is a robust solution for number formatting, there are several alternatives available that also cater to similar needs. Here are a few noteworthy options:
currency.js is a lightweight library specifically focused on currency manipulation. It allows developers to perform arithmetic operations on currency values while ensuring precision and accuracy. With features like formatting, conversion, and rounding, currency.js is particularly useful for applications that require extensive currency calculations. If your project primarily deals with currency and you need a library that emphasizes accuracy and simplicity, currency.js is an excellent choice.
dinero.js is another powerful library for handling money and currency in JavaScript. It provides a rich set of features for creating, manipulating, and formatting monetary values. With support for multiple currencies, rounding, and currency conversion, dinero.js is ideal for applications that require complex financial calculations. Its immutable design ensures that all operations return new instances, which can help prevent unintended side effects in your code. If your application demands a comprehensive solution for managing money, dinero.js is worth considering.
numeral is a library focused on number formatting, providing a flexible and powerful way to format numbers in various ways, including currency, percentages, and custom formats. While it does not have the same level of currency-specific features as currency.js or dinero.js, it is an excellent choice for applications that require versatile number formatting capabilities. If your primary need is to format numbers in different ways without the complexities of currency manipulation, numeral can be a great fit.
currency.js is a lightweight JavaScript library designed for handling currency calculations and formatting. It provides a simple and intuitive API for performing arithmetic operations on currency values while ensuring precision and accuracy. This makes it an excellent choice for developers working on financial applications, e-commerce platforms, or any project that requires handling monetary values. While currency.js is a robust solution for currency management, there are several alternatives available in the ecosystem. Here are a few notable ones:
currency-formatter is a library focused on formatting currency values for display. It allows developers to easily format numbers as currency strings based on locale and currency type. While it does not handle arithmetic operations like currency.js, it excels in providing a straightforward way to display currency values in a user-friendly format. If your primary need is to format currency for presentation rather than perform calculations, currency-formatter is a suitable choice.
dinero.js is a powerful library for creating and manipulating monetary values. It provides a comprehensive API for performing arithmetic operations, formatting, and handling currency conversions. Dinero.js is particularly useful for applications that require complex financial calculations, as it ensures precision and supports multiple currencies. If your project involves advanced currency management, such as handling discounts, taxes, or multi-currency transactions, dinero.js is a strong contender.
numeral is a library for formatting and manipulating numbers, including currency values. It provides a flexible way to format numbers as currency, percentages, and more. While it is not specifically designed for currency management like currency.js or dinero.js, it offers a versatile solution for general number formatting needs. If your application requires a broader range of number formatting capabilities beyond just currency, numeral is a good option.
numeral is a JavaScript library designed for formatting and manipulating numbers. It provides a simple and intuitive API for formatting numbers into various styles, such as currency, percentages, and more. This makes it a popular choice for developers who need to present numerical data in a user-friendly manner. While numeral is a robust solution for number formatting, there are several alternatives available that also cater to similar needs. Here are a few noteworthy options:
accounting is a lightweight JavaScript library for number formatting and manipulation, particularly focused on financial data. It provides functions for formatting currency, percentages, and numbers with thousands separators. If your application primarily deals with financial data and you need a straightforward way to format and manipulate numbers, accounting is a solid choice. Its simplicity and focus on financial use cases make it an appealing alternative to numeral.
d3-format is part of the D3.js library, which is widely used for data visualization. The d3-format module provides powerful formatting capabilities for numbers, including support for custom formats. If you're already using D3 for visualizations or need advanced formatting options, d3-format can be a great choice. It allows for extensive customization and is particularly useful when working with complex datasets that require specific formatting rules.
numbro is another library for formatting numbers, inspired by numeral.js. It offers a similar API and supports various formats, including currency, percentages, and more. numbro is designed to be lightweight and easy to use, making it a good alternative for developers looking for a straightforward number formatting solution. Its compatibility with numeral.js means that transitioning between the two libraries can be relatively seamless.
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);