accounting-js vs d3-format vs format-number vs mathjs vs numeral vs sprintf-js
JavaScript Number Formatting Libraries
accounting-jsd3-formatformat-numbermathjsnumeralsprintf-jsSimilar Packages:

JavaScript Number Formatting Libraries

These libraries provide various functionalities for formatting numbers, currencies, and mathematical expressions in JavaScript applications. They cater to different needs such as financial calculations, data visualization, and general number formatting, making it easier for developers to present numerical data in a user-friendly manner. Each library has its unique features, design principles, and use cases, allowing developers to choose the most suitable one based on their specific requirements.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
accounting-js011746.9 kB119 months agoMIT
d3-format064042.3 kB10a month agoISC
format-number051-69 years agoBSD-3-Clause
mathjs015,0049.41 MB17813 days agoApache-2.0
numeral09,728-3499 years agoMIT
sprintf-js02,13739.9 kB672 years agoBSD-3-Clause

Feature Comparison: accounting-js vs d3-format vs format-number vs mathjs vs numeral vs sprintf-js

Number Formatting

  • accounting-js:

    Accounting-js provides simple methods for formatting numbers and currencies, allowing developers to easily format values for display in financial applications. It supports customizable decimal and thousand separators, making it straightforward to present numerical data clearly.

  • d3-format:

    D3-format offers extensive formatting options tailored for data visualization, including support for scientific notation, percentages, and custom formats. It allows for precise control over how numbers are displayed in charts and graphs, catering specifically to the needs of data-driven applications.

  • format-number:

    Format-number focuses on basic number formatting, providing options for decimal places and thousands separators. It is lightweight and easy to implement, making it suitable for simple projects that require basic formatting without additional complexity.

  • mathjs:

    Mathjs includes number formatting as part of its broader mathematical capabilities. It allows for formatting numbers in various ways, including currency and percentage formats, while also supporting complex calculations and operations, making it a versatile choice for mathematical applications.

  • numeral:

    Numeral provides a rich set of formatting options for numbers, including currency, percentages, and custom formats. It is designed to handle internationalization, making it suitable for applications that need to present numbers in different locales consistently.

  • sprintf-js:

    Sprintf-js allows for formatted string output using a syntax similar to C's printf function. It is particularly useful for creating complex formatted strings that include numbers, providing flexibility in how numerical data is presented within strings.

Mathematical Operations

  • accounting-js:

    Accounting-js is primarily focused on formatting and does not provide advanced mathematical operations. It is best used in conjunction with other libraries for calculations.

  • d3-format:

    D3-format does not include mathematical operations; it is strictly for formatting numbers in the context of data visualization. It is meant to complement libraries that handle calculations.

  • format-number:

    Format-number is limited to formatting and does not support mathematical operations. It is designed for straightforward use cases where calculations are handled separately.

  • mathjs:

    Mathjs excels in mathematical operations, offering a wide range of functions for calculations, including algebra, calculus, and statistics. It is ideal for applications that require extensive mathematical capabilities alongside number formatting.

  • numeral:

    Numeral does not perform mathematical operations but focuses on formatting numbers. It is best used in scenarios where calculations are handled by other libraries.

  • sprintf-js:

    Sprintf-js does not perform mathematical operations; it is focused on string formatting. It is useful for outputting formatted strings that may include results from calculations done elsewhere.

Complexity and Learning Curve

  • accounting-js:

    Accounting-js has a low learning curve due to its simple API focused on formatting. It is easy to integrate and use for basic financial applications.

  • d3-format:

    D3-format may have a steeper learning curve for those unfamiliar with D3.js, as it is designed to work within that ecosystem. Understanding D3.js concepts is essential for effective use.

  • format-number:

    Format-number is straightforward and easy to learn, making it suitable for beginners who need basic formatting capabilities without complexity.

  • mathjs:

    Mathjs has a moderate learning curve due to its extensive features and capabilities. Users may need time to familiarize themselves with its API and mathematical functions, but it is well-documented.

  • numeral:

    Numeral is easy to learn and implement, with a clear API for formatting numbers. It is suitable for developers looking for a quick solution without extensive setup.

  • sprintf-js:

    Sprintf-js has a familiar syntax for those with a background in C or similar languages, making it easy to learn for those users. However, it may require some adjustment for those unfamiliar with formatted string output.

Localization Support

  • accounting-js:

    Accounting-js provides basic localization support for currency formatting, allowing developers to customize formats based on locale. However, it may not cover all localization needs comprehensively.

  • d3-format:

    D3-format supports locale-specific formatting, making it suitable for applications that need to present numbers according to regional conventions in data visualizations.

  • format-number:

    Format-number offers limited localization features, primarily focusing on basic formatting without extensive support for different locales.

  • mathjs:

    Mathjs includes localization support for number formatting, allowing users to format numbers according to regional conventions, making it versatile for international applications.

  • numeral:

    Numeral excels in localization, providing extensive options for formatting numbers based on different locales, making it ideal for applications targeting international audiences.

  • sprintf-js:

    Sprintf-js does not focus on localization; it is primarily concerned with string formatting. Developers may need to handle localization separately.

Extensibility

  • accounting-js:

    Accounting-js is lightweight and does not offer extensive extensibility options. It is designed for specific use cases related to financial data formatting.

  • d3-format:

    D3-format is highly extensible and can be integrated into D3.js visualizations, allowing developers to create custom formats and extend its functionality as needed.

  • format-number:

    Format-number is not designed for extensibility; it provides basic formatting features without options for customization or extension.

  • mathjs:

    Mathjs is highly extensible, allowing users to create custom functions and extend its capabilities. This makes it suitable for complex applications that require tailored mathematical solutions.

  • numeral:

    Numeral is somewhat extensible, allowing for custom formats, but it is primarily focused on the provided formatting options without extensive customization capabilities.

  • sprintf-js:

    Sprintf-js is not designed for extensibility; it focuses on string formatting and does not provide options for extending its functionality.

How to Choose: accounting-js vs d3-format vs format-number vs mathjs vs numeral vs sprintf-js

  • accounting-js:

    Choose accounting-js if you need a simple and lightweight solution for formatting and manipulating currency values, especially for financial applications. It provides straightforward methods for currency formatting, number formatting, and basic arithmetic operations without the overhead of complex features.

  • d3-format:

    Select d3-format if you are working with data visualization in D3.js and require precise control over number formatting. It is designed to work seamlessly with D3.js, offering a powerful and flexible way to format numbers, including support for locale-specific formatting and custom formats for charts and graphs.

  • format-number:

    Opt for format-number if you need a straightforward library for formatting numbers with options for decimal places and thousands separators. It is lightweight and easy to use, making it suitable for simple applications where advanced features are not necessary.

  • mathjs:

    Use mathjs if you require a comprehensive library for mathematical operations, including advanced calculations, units, and complex numbers. It offers extensive functionality beyond just formatting, making it ideal for applications that involve heavy mathematical computations and require a robust solution.

  • numeral:

    Choose numeral if you need a versatile library that provides a wide range of formatting options for numbers, currencies, and percentages. It is particularly useful for applications that require consistent number formatting across different locales and contexts, making it a good choice for international applications.

  • sprintf-js:

    Select sprintf-js if you are looking for a library that mimics the functionality of C-style string formatting. It is useful for creating formatted strings with numbers, allowing for precise control over the output format, making it ideal for applications that require detailed string manipulation.

README for accounting-js

NPM version

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

Documentation

Quickstart

Install

npm install accounting-js

Use

Format number

import { formatNumber } from 'accounting-js';

// Default usage
formatNumber(5318008);
// ⇨ 5,318,008

// Custom format
formatNumber(9876543.21, { precision: 3, thousand: " " });
// ⇨ 9 876 543.210

Format money

import { formatMoney } from 'accounting-js';

// Default usage
formatMoney(12345678);
// ⇨ $12,345,678.00

// European formatting (custom symbol and separators)
formatMoney(4999.99, { symbol: "€", precision: 2, thousand: ".", decimal: "," });
// ⇨ €4.999,99

Convert money to numeric

import { unformat } from 'accounting-js';

unformat('£ 12,345,678.90 GBP');
// ⇨ 12345678.9

Accounting toFixed()

// Native toFixed has rounding issues
(0.615).toFixed(2);
// ⇨ '0.61'

// With accounting-js
toFixed(0.615, 2);
// ⇨ '0.62'

Copyright (c) 2016-present Stanislav Lesnikov, MIT License

Copyright (c) 2014 Open Exchange Rates, MIT License