I spent quite some time searching for a currency API to use for currency conversions on websites. I eventually found Open Exchange Rates and their Money.js library, which is a great solution for handling currecny conversions on websites.

So here is a brief rundown of how to implement their Money.js library and API.

First off, you will need an API key from them, which can be attained for free from their website here. The link is slightly hidden compared to their paid options, and this limits you to 1000 API requests per month, but for a small website or developing, that should be enough.

To start using their API, you need to fetch the currencies list from their website and add the fetched data to the money.js initiated fx variable.

$.getJSON('http://openexchangerates.org/api/latest.json?app_id=APIKEY',function(data){
	if (typeof fx !==  "undefined" && fx.rates){
		fx.rates = data.rates;
		fx.base = data.base;
	}
	else{
		window.fxSetup = {
			rates: data.rates,
			base: data.base
		};
	}
});

The if statement is to check if the library has loaded or not. If it hasn’t, then we setup the fxSetup variable that money.js checks for configuration options.

Then to run any conversions, we use the fx.convert() function. You can use this in a parameterized version or chained:

fx.convert(1.99,{from:"USD",to:"NZD"});
fx.convert(1.99).from("USD").to("NZD");

A list of the different currency types available can be found at http://openexchangerates.org/api/currencies.json/.

And there we have it. Easy currency conversion with Money.js using the Open Exchange Rates API. You can get more information on Money.js and its other features like default from and to values on their website here