JavaScript number formatting libraries

share link

by vinitha@openweaver.com dot icon Updated: May 31, 2023

technology logo
technology logo

Guide Kit Guide Kit  

JavaScript number formatting libraries provide tools and functions to format, manipulate, and display numbers in a desired format. These libraries offer various features and customization options to handle number formatting tasks efficiently. Some popular JavaScript number formatting libraries include Numeral.js, accounting.js, Intl.NumberFormat (built-in JavaScript API), d3-format (part of D3.js), and numeral (a smaller alternative to Numeral.js). These libraries offer a wide range of features, and you can select the one that best fits your project's requirements in terms of functionality, ease of use, and performance. 

 

Let’s look at each library in detail. You can access package commands, installation notes, code snippets using the links below. 

Numeral-js: 

  • Numeral.js is a JavaScript library that provides a simple and powerful way to format, manipulate, and display numbers. 
  • This makes it easy to perform various manipulations on numbers, such as rounding, adding, subtracting, multiplying, and dividing, all in a single chain of method calls. 
  • It supports a wide range of formatting options, including decimals, separators, currencies, percentages, abbreviations, and more. You can easily specify the desired format using the library's API. 
  • The library supports localization, allowing you to format numbers according to different language and region settings. 

Numeral-jsby adamwdraper

JavaScript doticonstar image 9444 doticonVersion:2.0.6doticon
License: Permissive (MIT)

A javascript library for formatting and manipulating numbers.

Support
    Quality
      Security
        License
          Reuse

            Numeral-jsby adamwdraper

            JavaScript doticon star image 9444 doticonVersion:2.0.6doticon License: Permissive (MIT)

            A javascript library for formatting and manipulating numbers.
            Support
              Quality
                Security
                  License
                    Reuse

                      accounting.js: 

                      • Accounting.js is a lightweight JavaScript library designed for number formatting, currency handling, and simple accounting operations 
                      • This includes specifying the default currency symbol, currency precision (number of decimal places), and currency symbol placement (before or after the number). 
                      • It provides locale-specific formatting options, such as decimal separators, thousand separators, and currency symbols. 
                      • It provides functions to format numbers with decimal precision, apply thousand separators, and customize the formatting of negative numbers. 

                      accounting.jsby openexchangerates

                      JavaScript doticonstar image 4874 doticonVersion:Currentdoticon
                      License: Permissive (MIT)

                      A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.

                      Support
                        Quality
                          Security
                            License
                              Reuse

                                accounting.jsby openexchangerates

                                JavaScript doticon star image 4874 doticonVersion:Currentdoticon License: Permissive (MIT)

                                A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
                                Support
                                  Quality
                                    Security
                                      License
                                        Reuse

                                          numeric: 

                                          • Numeric.js provides a fluent API that allows you to chain multiple operations together. 
                                          • It supports formatting options such as decimals, separators (e.g., commas), currency symbols, percentages, abbreviations, and more. 
                                          • Numeric.js is a lightweight library with a simple and intuitive API. It is easy to include in your JavaScript projects and requires minimal setup. 
                                          • You can specify the desired locale or let Numeral.js automatically detect the user's browser locale. 

                                          numericby sloisel

                                          JavaScript doticonstar image 1396 doticonVersion:Currentdoticon
                                          License: Others (Non-SPDX)

                                          Numerical analysis in Javascript

                                          Support
                                            Quality
                                              Security
                                                License
                                                  Reuse

                                                    numericby sloisel

                                                    JavaScript doticon star image 1396 doticonVersion:Currentdoticon License: Others (Non-SPDX)

                                                    Numerical analysis in Javascript
                                                    Support
                                                      Quality
                                                        Security
                                                          License
                                                            Reuse

                                                              numbro: 

                                                              • Numbro focuses on simplicity, performance, and internationalization, making it suitable for a wide range of number-related tasks in JavaScript applications. 
                                                              • It supports a wide range of locales, allowing you to customize the number formatting based on specific cultural conventions. 
                                                              • The library provides extensive localization support, enabling you to format numbers based on different language and region settings. 
                                                              • You can define your own formatting patterns, including the number of decimal places, separators, currency symbols, and more. 

                                                              numbroby BenjaminVanRyseghem

                                                              JavaScript doticonstar image 988 doticonVersion:2.3.6doticon
                                                              License: Permissive (MIT)

                                                              A JS library for number formatting

                                                              Support
                                                                Quality
                                                                  Security
                                                                    License
                                                                      Reuse

                                                                        numbroby BenjaminVanRyseghem

                                                                        JavaScript doticon star image 988 doticonVersion:2.3.6doticon License: Permissive (MIT)

                                                                        A JS library for number formatting
                                                                        Support
                                                                          Quality
                                                                            Security
                                                                              License
                                                                                Reuse

                                                                                  humanize: 

                                                                                  • humanize-plus includes functions to humanize numbers by adding appropriate separators, abbreviations, and units. 
                                                                                  • It provides capabilities for formatting large numbers, ordinal numbers, rounding numbers, and more. 
                                                                                  • This is useful when presenting file size information to users, making it easier for them to understand the magnitude of file sizes. 
                                                                                  • Humanize-plus provides functions to convert file sizes into a more readable format. It can format file sizes in bytes, kilobytes, megabytes, gigabytes, and beyond. 

                                                                                  humanizeby HubSpot

                                                                                  JavaScript doticonstar image 905 doticonVersion:v1.8.3doticon
                                                                                  License: Permissive (MIT)

                                                                                  A simple utility library for making the web more humane. #hubspot-open-source

                                                                                  Support
                                                                                    Quality
                                                                                      Security
                                                                                        License
                                                                                          Reuse

                                                                                            humanizeby HubSpot

                                                                                            JavaScript doticon star image 905 doticonVersion:v1.8.3doticon License: Permissive (MIT)

                                                                                            A simple utility library for making the web more humane. #hubspot-open-source
                                                                                            Support
                                                                                              Quality
                                                                                                Security
                                                                                                  License
                                                                                                    Reuse

                                                                                                      d3-format: 

                                                                                                      • d3-format library is a part of the D3.js (Data-Driven Documents) ecosystem and provides a set of functions for formatting numbers, dates, and other values in a customizable way. It 
                                                                                                      • It supports various formatting options for displaying dates and times in different formats, including year, month, day, hour, minute, second, and more. 
                                                                                                      • The library provides localization support, allowing you to format numbers and dates according to different locales and language conventions. 
                                                                                                      • It supports scaling numbers and displaying them in a more human-readable format with prefixes like kilo (K), mega (M), giga (G), etc. This is particularly useful when working with large or small numbers. 
                                                                                                      JavaScript doticonstar image 573 doticonVersion:v3.1.0doticon
                                                                                                      License: Permissive (ISC)

                                                                                                      Format numbers for human consumption.

                                                                                                      Support
                                                                                                        Quality
                                                                                                          Security
                                                                                                            License
                                                                                                              Reuse

                                                                                                                d3-formatby d3

                                                                                                                JavaScript doticon star image 573 doticonVersion:v3.1.0doticon License: Permissive (ISC)

                                                                                                                Format numbers for human consumption.
                                                                                                                Support
                                                                                                                  Quality
                                                                                                                    Security
                                                                                                                      License
                                                                                                                        Reuse

                                                                                                                          format-number 

                                                                                                                          • A number formatting library in JavaScript, like "number-formatter," is designed to facilitate the formatting and manipulation of numbers in a customizable way. 
                                                                                                                          • The library allows you to format numbers based on various criteria, such as decimal places, separators (e.g., commas), significant figures, currency symbols, percentage symbols, and more 
                                                                                                                          • They allow you to format numbers according to different locales, language conventions, and currency formats. 
                                                                                                                          • This can include defining custom patterns, specifying the position of symbols, choosing rounding methods, and configuring other formatting preferences. 

                                                                                                                          format-numberby componitable

                                                                                                                          JavaScript doticonstar image 48 doticonVersion:Currentdoticon
                                                                                                                          License: Permissive (BSD-3-Clause)

                                                                                                                          Formats numbers with separators every 3 digits and currency etc. Highly configurable.

                                                                                                                          Support
                                                                                                                            Quality
                                                                                                                              Security
                                                                                                                                License
                                                                                                                                  Reuse

                                                                                                                                    format-numberby componitable

                                                                                                                                    JavaScript doticon star image 48 doticonVersion:Currentdoticon License: Permissive (BSD-3-Clause)

                                                                                                                                    Formats numbers with separators every 3 digits and currency etc. Highly configurable.
                                                                                                                                    Support
                                                                                                                                      Quality
                                                                                                                                        Security
                                                                                                                                          License
                                                                                                                                            Reuse

                                                                                                                                              FAQ: 

                                                                                                                                              1. What is a JavaScript number formatting library?   

                                                                                                                                              A JavaScript number formatting library is a software package or tool that provides functions, methods, or utilities for formatting numbers in a desired format. It helps developers manipulate and present numerical data in a human-readable and localized manner. These libraries typically offer a range of options to customize how numbers are displayed, including decimal places, separators, currency symbols, percentage symbols, and more. 

                                                                                                                                               

                                                                                                                                              2. How can I use the JavaScript Internationalization API to format currency formatted numbers?   

                                                                                                                                              To format currency formatted numbers using the JavaScript Internationalization (Intl) API, you can utilize the Intl.NumberFormat object, which provides built-in support for formatting numbers according to specific locales and currency formats. By using the Intl.NumberFormat object and specifying the appropriate locale and currency options, you can format numbers as currency according to the conventions of different regions and languages. 

                                                                                                                                               

                                                                                                                                              3. What is the format function used for in a number formatting library?   

                                                                                                                                              The format function in a number formatting library is a core feature that allows you to transform a numerical value into a formatted string representation according to specific formatting rules and patterns. It takes a number as input and applies the desired formatting options to produce the formatted string output. 

                                                                                                                                              The format function typically accepts one or more parameters, depending on the library and its specific implementation. The most common parameter is the number you want to format. It can be a numeric value, such as an integer or a floating-point number. 

                                                                                                                                               

                                                                                                                                              4. How can I specify decimal values when using a number formatting library?   

                                                                                                                                              When using a number formatting library, you can typically specify the decimal values by using formatting options or parameters provided by the library. The specific method for specifying decimal values may vary depending on the library you are using, but here are some common approaches: 

                                                                                                                                              • Decimal Places 
                                                                                                                                              • Rounding 
                                                                                                                                              • Truncation 

                                                                                                                                               

                                                                                                                                              5. What are locale strings and how do they work for numeric formatting libraries?   

                                                                                                                                              locale strings, in the context of numeric formatting libraries, are strings that represent a specific locale or language region. They are used to define the formatting rules and conventions for numbers in that particular locale. 

                                                                                                                                              A locale string typically consists of two parts: a language code and a region code, separated by a hyphen. For example, "en-US" represents the English language in the United States, while "de-DE" represents German in Germany. The language code represents the primary language, and the region code represents the specific country or region associated with that language. 

                                                                                                                                              When using numeric formatting libraries, you can specify a locale string as a parameter or option to indicate the desired formatting rules based on a specific locale. The library will then apply the appropriate formatting conventions for numbers in that locale, including decimal separators, thousands of separators, currency symbols, and other formatting preferences. 

                                                                                                                                              See similar Kits and Libraries