accounting-js vs numeral
Number Formatting Libraries
accounting-jsnumeralSimilar Packages:

Number Formatting Libraries

Number formatting libraries in JavaScript provide tools to format numbers for display purposes, such as adding commas, formatting currencies, percentages, and more. These libraries help ensure that numbers are presented in a readable and culturally appropriate way, which is especially important for financial applications, e-commerce sites, and any application that displays numerical data to users. accounting-js is a lightweight library focused on simple and intuitive formatting of currencies, numbers, and percentages, while numeral is a more feature-rich library that offers extensive formatting options, including support for custom formats, currencies, and localization.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
accounting-js011746.9 kB11a year agoMIT
numeral09,715-3499 years agoMIT

Feature Comparison: accounting-js vs numeral

Size and Performance

  • accounting-js:

    accounting-js is a small library (around 2KB minified) that provides basic number and currency formatting. Its lightweight nature makes it ideal for projects where performance and load times are a concern.

  • numeral:

    numeral is slightly larger (around 7KB minified) but offers more advanced features and flexibility. The trade-off in size is worth it for applications that need more robust formatting capabilities.

Currency Formatting

  • accounting-js:

    accounting-js specializes in currency formatting, allowing you to easily format numbers as currency with customizable symbols, decimal places, and thousand separators. It is simple to use and provides sensible defaults.

  • numeral:

    numeral also supports currency formatting but offers more flexibility in terms of customizing formats and symbols. It allows for more complex formatting scenarios, including multiple currencies and dynamic symbol changes.

Custom Formats

  • accounting-js:

    accounting-js has limited support for custom formats, focusing primarily on currency, number, and percentage formatting. It is designed to be simple and easy to use, which means it doesn’t have a lot of advanced features.

  • numeral:

    numeral excels in custom formatting, allowing you to define your own formats for numbers, currencies, and percentages. This makes it a better choice for applications that require more complex or non-standard formatting.

Localization

  • accounting-js:

    accounting-js has basic support for localization, allowing you to customize decimal and thousand separators. However, it does not have built-in support for multiple locales or automatic localization.

  • numeral:

    numeral has better support for localization, including the ability to define multiple locales and switch between them. This makes it more suitable for applications that need to support multiple languages and regional formats.

Ease of Use: Code Examples

  • accounting-js:

    Simple currency formatting with accounting-js

    const accounting = require('accounting-js');
    const formattedCurrency = accounting.formatMoney(1234567.89);
    console.log(formattedCurrency); // $1,234,567.89
    
  • numeral:

    Simple currency formatting with numeral

    const numeral = require('numeral');
    const formattedCurrency = numeral(1234567.89).format('$0,0.00');
    console.log(formattedCurrency); // $1,234,567.89
    

How to Choose: accounting-js vs numeral

  • accounting-js:

    Choose accounting-js if you need a simple, lightweight solution for formatting currencies, numbers, and percentages. It is particularly useful for projects that require straightforward formatting without a lot of configuration.

  • numeral:

    Choose numeral if you need a more comprehensive solution with advanced formatting capabilities, including support for custom formats and localization. It is ideal for applications that require more flexibility and features.

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