// The <pre> tag enables the code to be viewed in a browser... //
// worldpay_currency.php
// By: Nick Sumner, dev@nicksumner.com 
// ECommerce Integration - http://www.tele-pro.co.uk/
// Running in JavaScript mode
// Rates Date: 2010-09-02
// Data Cached: true

// variable indicates if data cached
var fromCache = true;

// variable for date of cache
var ratesDate = '2010-09-02';

// variable contains raw data 
var rawCurrencyData = '#Thu Sep 02 00:01:52 GMT 2010\n' + 
'GBP_USD=1.5985858130708306\n' + 
'rateDateString=2010-09-02\n' + 
'rateDateMillis=1283385600000\n' + 
'lastUpdated=1283385712000\n' + 
'allRatesCurrent=false\n' + 
'GBP_GBP=1.0\n' + 
'GBP_EUR=1.2604161579049362';

// variable for text list
var htmlCurrencyList = 'USD (1.599)
GBP (1.000)
EUR (1.260)
'; // variable for table list var htmlCurrencyTable = '
USD 1.599
GBP 1.000
EUR 1.260
'; // define Array for Currencies var WorldpayCurrencies = new Array(); WorldpayCurrencies['USD']='1.59858581'; WorldpayCurrencies['GBP']='1.00000000'; WorldpayCurrencies['EUR']='1.26041616'; // Convert amount with Worldpay currency rate function WorldpayConvert(amount, currency, dp){ var result=0; // get the rate var rate = WorldpayCurrencies[currency]; // does the currency exist? if (rate == 0) return result; // convert the amount to the currency result = (amount * rate); // number format dp result = numberFormat(result, dp); // return return result; } // format number n to p decimal places function numberFormat(n, p){ var d = Math.pow(10,p); var r = (Math.round(d * n) /d); return r; }