472,378 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Urgent Help with currency exchange

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
7 3883
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
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
<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
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
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
>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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andie | last post by:
Hello All, I am writing a script than connects to my database and pulls prices in pounds, does anyone know how I can get the current exchange rate so I can have a dual currency on my site. I...
7
by: Ted | last post by:
I've written a little function to remove everything after the 2nd decimal place for prices which is as follows: - ReturnConvertedCurrency = (fix(iSterling * session("ExchangeRate") * 100) / 100)...
1
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime),...
2
by: Baybars | last post by:
New to access, but to deja.com. Looked through many posts, but can not find a good post for my problem (I believe there is, but my access level didn't allow me to understand). I have a table for...
13
by: Redduck | last post by:
Hello everyone. I am frustrated, I have written the simple program below for a class and I am having problems with the DO-WHILE loop. On the first run through the loop, everything works well, the...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
8
by: CJK | last post by:
i have a currency class which is as follows #include <string> #include <sstream> #include <cmath> using namespace std; #include "Tokeniser.h" #include "Utilities.h"
1
by: Eric | last post by:
I've built a Currency class, more or less like Java's, a Money class to handle rounding and allocation, and a Moneybag that should collect different monies and convert them to a given exchange...
16
by: Alexio | last post by:
Am new to javascript. I need to format the currency in the as numbers are entered in textboxes. I can format the currency in the calculations and display in the totals but can not figure out how to...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.