You are here: Re: Urgent Help with currency exchange « PHP Programming Language « IT news, forums, messages
Re: Urgent Help with currency exchange

Posted by Treefrog on 10/20/63 11:43

meenasamy@hotmail.com wrote:
> Hi all, i need to create a function that takes three parameters(
> Original currency, needed currency, amount) i need to convert from the
> original currency to the needed currency the amount and return the new
> amount in the needed currency, I need this function to work real time
> (obtaining real time currency exchange rates), any ideas???

Here's one a wrote earlier.
You need to buy (or scrape ;o) data from www.oanda.com or xe or
wherever, the program I wrote stores it in a database. I needed
historical data as well as current exchange rates, hence the date
field. $source and $dest are the three letter currency code e.g. "GBP"
or "USD".

The function getRate returns the exchange rate (from the db) in
relation to GBP for the given date... although, any "intermediate"
currency will work, I chose GBP because that's my local flavour.

function exchange($source,$dest,$amount,$date=null)
{
// if there's no date, then presume today.
if ($date==null)
{
$date = date("Ymd");
}

// GET SOURCE DATA
$sourceRate = getRate($source,$date);


// GET DEST DATA.
$destRate = getRate($dest,$date);


// convert "amount" from sourceRate to GBP
if ($sourceRate > 0 && $destRate > 0)
{
$sourceGBP = $amount * $sourceRate;
$destAmount = $sourceGBP / $destRate;
return round($destAmount,2);
}
else
{
return false;
}
} // end function exchange

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация