JavaScript currency conversion library – money.js

Simple JavaScript currency conversion library with no dependencies, small and easy to use.

Good JavaScript currency conversion library

Money.js library was designed to work seamlessly with data from the Open Exchange Rates API – or any other data source and base currency, with just a few lines of setup. Use standalone, or as a nodeJS/npm or RequireJS (AMD) module.

Money.js - JavaScript currency conversion library
Money.js – JavaScript currency conversion library

Sample code:

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

// Chaining sugar:
fx(1000).from("USD").to("GBP");
fx(1000).to("AED");

// With simple settings and defaults, making this possible:
fx.convert(5318008);
fx(5318008).to("AED");

// Can also be used as a nodeJS/npm or requireJS/AMD module
var fx = require("money");
require(["money"], function(fx) { /* ... */ });

Only the rates must be defined:

fx.base = "USD";
fx.rates = {
  "EUR" : 0.745101, // eg. 1 USD === 0.745101 EUR
  "GBP" : 0.647710, // etc...
  "HKD" : 7.781919,
  "USD" : 1,        // always include the base rate (1:1)
  "CHF" : ... /* etc */
}

In fact we can create a script, to keep these settings up to date automatically.

Demo and great documentation we can find at project homepage:

http://openexchangerates.github.io/money.js

GitHub:

https://github.com/openexchangerates/money.js

Bonus

Maybe also this library – accounting.js – would be interesting for you:

http://openexchangerates.github.io/accounting.js

Enjoy$!