Connecting Tech Pros Worldwide Forums | Help | Site Map

Urgent Help with currency exchange

meenasamy@hotmail.com
Guest
 
Posts: n/a
#1: Mar 28 '06
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???


Treefrog
Guest
 
Posts: n/a
#2: Mar 28 '06

re: Urgent Help with currency exchange


meenasamy@hotmail.com wrote:[color=blue]
> 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???[/color]

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

Geoff Berrow
Guest
 
Posts: n/a
#3: Mar 28 '06

re: Urgent Help with currency exchange


Message-ID: <1143533587.102091.31550@v46g2000cwv.googlegroups. com> from
meenasamy@hotmail.com contained the following:
[color=blue]
>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???[/color]

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/
Kimmo Laine
Guest
 
Posts: n/a
#4: Mar 28 '06

re: Urgent Help with currency exchange


<meenasamy@hotmail.com> wrote in message
news:1143533587.102091.31550@v46g2000cwv.googlegro ups.com...[color=blue]
> 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???[/color]


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ö
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Treefrog
Guest
 
Posts: n/a
#5: Mar 28 '06

re: Urgent Help with currency exchange


Geoff Berrow wrote:[color=blue]
> Message-ID: <1143533587.102091.31550@v46g2000cwv.googlegroups. com> from
> meenasamy@hotmail.com contained the following:
>[color=green]
> >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???[/color]
>
> Like treefrog says, scraping the data is one way. Like this:
>
> www.ckdog.co.uk/dev/rates2.php
>[/color]

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?

NC
Guest
 
Posts: n/a
#6: Mar 28 '06

re: Urgent Help with currency exchange


meenasamy@hotmail.com wrote:[color=blue]
>
> 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???[/color]

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

Meena
Guest
 
Posts: n/a
#7: Mar 29 '06

re: Urgent Help with currency exchange


>If you're using currency exchange, then I guess you're dealing with a[color=blue]
>multilanguage project?[/color]
[color=blue]
>Just curious, but how are you dealing with different charsets and
>languages for your content?[/color]


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

Meena
Guest
 
Posts: n/a
#8: Mar 29 '06

re: Urgent Help with currency exchange


>If you're using currency exchange, then I guess you're dealing with a[color=blue]
>multilanguage project?[/color]
[color=blue]
>Just curious, but how are you dealing with different charsets and
>languages for your content?[/color]


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

Closed Thread