Currency conversion and money formating libraries in Javascript


These are 2 very useful Javascript libraries for dealing with money currency and formatting written by Joss Crowcroft.

Currency conversion with money.js

money.js is a currency conversion library with no dependencies, in just over 1 KB. You could provide your own currency rates in JSON format or use the data from the Open Source Exchange Rates project which is also created by Joss Crowcroft and looks very promising!

Usage examples:

// From any currency, to any currency:
fx.convert(12.99, {from: "GBP", to: "HKD"});

// Chaining:

// With simple settings and defaults, making this possible:

Money formatting with accounting.js

accounting.js is a small 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 no dependencies.

I've been using accounting.js for a month -in the administration panel of an e-commerce system- and had zero problems so far.

Usage examples:

// 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

// Simple `format` string allows control of symbol position [%v = value, %s = symbol]:
accounting.formatMoney(5318008, { symbol: "GBP",  format: "%v %s" }); // 5,318,008.00 GBP

// Formatting numbers
accounting.formatNumber(5318008); // 5,318,008
accounting.formatNumber(9876543.21, 3, " "); // 9 876 543.210

// Unformatting numbers / currency strings
accounting.unformat("£ 12,345,678.90 GBP"); // 12345678.9


Jason  •  March 6, 2013 03:49

accounting.formatMoney(4999.99, "€", 2, ".", ","); // €4.999,99 -> this is useless.

Fredy  •  October 4, 2013 12:07

I think you do not see the big picture

if you replace the 4999.99 by a variable then this function is very useful

Ermir  •  April 28, 2014 13:42

Hey thanks for this great information :) Was a pleasure reading it :)

obat perangsang wanita  •  June 24, 2014 12:00

wanita sedikit bingung disaat hubungan seksualnya sudah berkurang maka dari itu mereka takut jika pasangannya berpaling darinya oleh karena itu ini saat yang tepat dan cepat membangkitkan libido dengan obat perangsang wanita herbal alami dan sangat aman.

Post your comment

(optional, will not be shown)
NOTE: Any links will have rel="nofollow"