// 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-07
// Data Cached: true

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

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

// variable contains raw data 
var rawCurrencyData = '#Tue Sep 07 03:44:47 GMT 2010\n' + 
'GBP_USD=1.6049092806367384\n' + 
'rateDateString=2010-09-07\n' + 
'rateDateMillis=1283817600000\n' + 
'lastUpdated=1283831087000\n' + 
'allRatesCurrent=false\n' + 
'GBP_GBP=1.0\n' + 
'GBP_EUR=1.2441157214238283';

// variable for text list
var htmlCurrencyList = 'USD (1.605)
GBP (1.000)
EUR (1.244)
'; // variable for table list var htmlCurrencyTable = '
USD 1.605
GBP 1.000
EUR 1.244
'; // define Array for Currencies var WorldpayCurrencies = new Array(); WorldpayCurrencies['USD']='1.60490928'; WorldpayCurrencies['GBP']='1.00000000'; WorldpayCurrencies['EUR']='1.24411572'; // 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; }