Categories
Uncategorized

An introduction to accounting.js, a javascript library for number, money and currency formatting

accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). It’s lightweight, fully localisable and has zero dependencies. This JavaScript library can be downloaded from here

Why to use accounting.js ? 
* Its open source 
* Lightweight : Latest version from Github (3kb, minified
* Fully localisable and has zero dependencies.

Where to use accounting.js ? 
Can be used in finance and accounting, reporting apps for adding client-side number formatting.

Key features of accounting.js: 
* Control decimal place 
* Rounding for floating point numbers 
* Excel-style column rendering (to line up symbols and decimals) 
* Money formatting Below are few examples from the docs :

.formatMoney() :

// Default usage: 
accounting.formatMoney(12345678); // $12,345,678.00
// European formatting (custom symbol and separators), could also use options object as second param:
accounting.formatMoney(4999.99, "€", 2, ".", ","); // €4.999,99
// Negative values are formatted nicely, too:
accounting.formatMoney(-500000, "£ ", 0); // £ -500,000
.formatNumber() :
accounting.formatNumber(5318008); // 5,318,008
accounting.formatNumber(9876543.21, 3, " "); // 9 876 543.210
.toFixed() :
(0.615).toFixed(2); // "0.61"
accounting.toFixed(0.615, 2); // "0.62"
Hope this helps :)
Further Reading : 
* Currency conversion and money formating libraries in Javascript
* Github - accounting.js