Use Accounting.js to Format Numbers, Money and Currency

When building a new website, we all need the advanced features like Formatting numbers, money and currency in its proper units and decimals which are indeed a cumbersome process when it comes doing it by pure coding. Not everyone is a coder and comfortable enough to play with Code and make their hands dirty with it. So here comes Accounting.js for the rescue as using this javascript library anyone can implement numbers in proper currency format or can split numbers with exact commas or decimal points.

Seriously speaking, Accounting.js – A light-weight JavaScript library for Numbers, Money and Currency formatting is really awesome. It is also very easy and convenient to use. So, let’s go dive to the Accounting.js Tutorial and get started with it.


Let’s learn about Accounting.js a bit more deeply:

How to Use Accounting.js?

The very first step to using Accounting.js is to include the javascript files into the head section.

Just download the Accounting.js javascript files from GitHub Repository and include it in the <head> section of your web page. This section is normally found in a file called Header. If you are using a popular CMS like WordPress, then you can find the <head> section in the file header.php

The first one we are going to learn in Accounting.js is:

1. formatNumber():

This option in Accounting.js lets various numbers and digits properly formatted and separated with thousands and custom precision.

The function takes an array of numbers and runs the javascript code to remove any pre-defined formatting, and returns the number(s) formatted in a proper way.

Below is the complete program for more precision:

2. formatMoney():

This Accounting.js option will enable formatting any number into proper currency format.

The Javascript Code:

The more precise Javascript code for custom currency formatting:

Recommended Readings:

3. toFixed():

Numbers with float as a datatype can be rounded off to a proper format using Accouting.js toFixed() function. Here’s how:

More Precise Code:

4. unformat():

This accounting.js function lets user convert any formatted number or any currency string to a unformatted number.

5. formatColumn():

A list of numbers will be formatted to proper format in proper columns using the formatColumn() function of Accounting.js.

Original Value Formatted Column Value
123.5 $ 123.50
3456.49 $ 3,456.5
777888.99 $ 777,888.99
1234567 $ 1,234,567.00
-5432 $ -5,432.00

This was some of the common functions of Accounting.js which are quite accessible and feasible for use and can be applied to any set of numbers on a web page.

Accounting.js is really a lightweight library that enables a user to format or unformat a set of numbers or array of numbers.

This Javascript library is of 3KB and is really very handy if you are dealing with a large set of data in numbers.

Use this javascript library and get an immediate rescue from the trouble of formatting numbers.

(Visited 154 times, 2 visits today)
Share is Caring...!

Leave a Reply