By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Urgent Help with currency exchange

P: n/a
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???

Mar 28 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
me*******@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

Mar 28 '06 #2

P: n/a
Message-ID: <11*********************@v46g2000cwv.googlegroups. com> from
me*******@hotmail.com contained the following:
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???


Like treefrog says, scraping the data is one way. Like this:

www.ckdog.co.uk/dev/rates2.php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 28 '06 #3

P: n/a
<me*******@hotmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
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???

Currency conversion rates are usually given in reference to another
currency. To convert 1 euro to us dollars, I'd need to know either how many
dollars one euro is, or how many euros one dollar is. Google currency
convertor gives a rate of 1 Euro = 1.20300 U.S. dollars. That means with 1
euro I can buy 1 dollar and 20 cents. Now, if I want to convert a random
amount of euros to dollars, for example 20 euros, I'd just multiply 20 euros
with the rate 1.20300 and presto, I get 24.06 dollars. That's just simple
math. The hard part is obtaning the rate.

As you might've guessed already that php does not have a built in currency
exchange rate function that would real-time fetch the currencies. How to
obtain the currency rates, real-time? Well, Google is your friend as always
(in fact it has a built-in currency converter but they do not gurantee
accuracy), you can search for methods of obtaning the exhange rates. Getting
them real-time requires communication with a third party service. I found
for an example a website called xmethods ( http://www.xmethods.com/ ) that
lists a wide range of services and among these, php libraries for obtaning
currency exchange rates via communicating with a third party server.

HTH.

Ps. I hope the "urgent" was just a joke because I'd estimate researching the
methods and implementing it takes time...

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 28 '06 #4

P: n/a
Geoff Berrow wrote:
Message-ID: <11*********************@v46g2000cwv.googlegroups. com> from
me*******@hotmail.com contained the following:
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???


Like treefrog says, scraping the data is one way. Like this:

www.ckdog.co.uk/dev/rates2.php


If you're using currency exchange, then I guess you're dealing with a
multilanguage project?

Just curious, but how are you dealing with different charsets and
languages for your content?

Mar 28 '06 #5

P: n/a
NC
me*******@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???


Just scrape any Web page that lists the exchange rate you need. Some
possible sources:

http://www.bloomberg.com/markets/currencies/fxc.html
http://finance.yahoo.com/currency
http://fx.sauder.ubc.ca/data.html

The latter two also allow you to obtain data in CSV format. You just
need to figure out how to form the URL to obtain exactly the data you
need. When you have the rate, conversion of the amount becomes
trivial...

Cheers,
NC

Mar 28 '06 #6

P: n/a
>If you're using currency exchange, then I guess you're dealing with a
multilanguage project? Just curious, but how are you dealing with different charsets and
languages for your content?

I tried to use multiple languages but found out it needs a lot of time,
you can use localization by managing a cataloge for the words and
phrases and check on the lang. when using the phrases

Mar 29 '06 #7

P: n/a
>If you're using currency exchange, then I guess you're dealing with a
multilanguage project? Just curious, but how are you dealing with different charsets and
languages for your content?

I tried to use multiple languages but found out it needs a lot of time,
you can use localization by managing a cataloge for the words and
phrases and check on the lang. when using the phrases

Mar 29 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.