Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2008, 11:09 AM   PM User | #1
many_tentacles
Regular Coder

 
Join Date: Dec 2005
Location: UK
Posts: 207
Thanks: 6
Thanked 2 Times in 2 Posts
many_tentacles is an unknown quantity at this point
currency conversions...

Hi

I have this code which works fantastically.

Code:
<script type="text/javascript">
exchRate = 1.3; 
function getUSD(price) { 
document.write('(' + price * exchRate + ' &euro;)'); 
}
</script>
<p>Price: &pound;1.40 <script type="text/javascript"> getUSD('1.4'); </script></p>
However, it will require someone changing the exchange rate manually as it changes. So my first question is this... Is there any way I can grab the latest exchange rate from a 3rd party??

Secondly, I need to display the converted price rounded to 2 decimal places. I'm sure I'll be able to work this one out with a little searching around, but any help would be appreciated.

Many thanks.
many_tentacles is offline   Reply With Quote
Old 10-20-2008, 11:31 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
"So my first question is this... Is there any way I can grab the latest exchange rate from a 3rd party??"

No, not with Javascript. There are various RSS feeds available.
See: e.g. http://www.xe.com/dfs/ and Google for others.
A free currency converter is provided by:-
http://www.currencysource.com/webmasters.html

"Secondly, I need to display the converted price rounded to 2 decimal places."

Code:
<script type="text/javascript">
var exchRate = 1.3; 
function getUSD(price) { 
var np = (price * exchRate).toFixed(2);
document.write('(' + np + ' &euro;)'); 
}
</script>
<p>Price: &pound;1.40 <script type="text/javascript"> getUSD('1.4'); </script></p>

"Can you do addition?" the White Queen asked. "What's one and one and one and one and one and one and one and one and one and one?" "I don't know," said Alice. "I lost count." - Lewis Carroll

Last edited by Philip M; 10-20-2008 at 12:19 PM.. Reason: More info
Philip M is offline   Reply With Quote
Old 10-20-2008, 12:18 PM   PM User | #3
many_tentacles
Regular Coder

 
Join Date: Dec 2005
Location: UK
Posts: 207
Thanks: 6
Thanked 2 Times in 2 Posts
many_tentacles is an unknown quantity at this point
Thanks for that.

OK, so we've established that it's not easy to automate the exchange rate updating...

Is it possible using ASP.net??

Otherwise, what is the best service that I can pay for. Ideally with little or no banners. Is it the XE.com one you mentioned?

Thanks
many_tentacles is offline   Reply With Quote
Old 10-20-2008, 12:22 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Google for currency converter rss feeds

A free currency converter is provided by:-
http://www.currencysource.com/webmasters.html
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:39 AM.


Advertisement
Log in to turn off these ads.