homepage Welcome to WebmasterWorld Guest from 54.205.241.107
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Showing different currencies on product pages
then updating the exchange rate once a week
usavetele

10+ Year Member



 
Msg#: 3893 posted 3:28 am on Jun 18, 2005 (gmt 0)

Hello,

I signed up for an affiliate who's products are sold in EURO. Needless to say, I'd like to display the prices in USD as well as some other currencies. I found the following code for showing EURO prices and the USD equivilant based on the exchange rate I put into the code.

My question is: How do I round the USD price so it reads like normal currency, with cents? I obviosuly don't want to display $51.588674

Also, how can I format the prices in bold, and line the prices one on top of the other?

added in header:
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from older browsers
function EurToUSD(EUR, ExchRate)
{
var USD = EUR * ExchRate;
return USD;
}

function USDToEur(USD, ExchRate)
{
var EUR = USD / ExchRate;
return EUR;
}
// End Hide -->
</SCRIPT>

added in body of page:
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from older browsers
var ExchRate = 1.2;
var EUR = 42.99;
var anumber=42.99
anumber.toFixed(2) //returns 42.99(round up)
var USD = EurToUSD(EUR, ExchRate);
document.write("Euro" + EUR + "US$<BR>" + USD);

// End Hide -->
</SCRIPT>

 

JAB Creations

WebmasterWorld Senior Member jab_creations us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3893 posted 3:32 am on Jun 18, 2005 (gmt 0)

Most people know that currencies change on a daily basis, so I'd imagine there must be something online that sites can make reference to in order to display the most up to date exchange rates. Your question should be that--unless you want to go down the path of explaining why you may (in the customers perspective) be ripping people off via currency tricks (not saying you are). If you find such a site let me know, I'd love to add it to my bookmarks!

usavetele

10+ Year Member



 
Msg#: 3893 posted 3:40 am on Jun 18, 2005 (gmt 0)

"there must be something online that sites can make reference to in order to display the most up to date exchange rates"

I don't want to clutter my pages with a display of the exchange rates. I want to have prices displayed in USD for the most part, but since my affiliate shows the EURO price, I'm stuck on how to do this the most efficient and FREE way. I plan to put a disclaimer up saying these prices are subject to the daily change in the exchange rate. And these prices are faily close to the selling price (within cents).

JAB Creations

WebmasterWorld Senior Member jab_creations us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3893 posted 5:06 am on Jun 18, 2005 (gmt 0)

You could try giving an estimate based on general ranges. Find a reliable site that (will hopefully) show you the general trend of currencies, their high and low points, decide an average, and of course state your sources which your convertions are based on.

1.5 us / 1.9 ca *
*Based on avg us/ca rates, (url here).

usavetele

10+ Year Member



 
Msg#: 3893 posted 5:13 am on Jun 18, 2005 (gmt 0)

Well that's a good idea, but that only solves one part of my problems. I like your wording for the disclaimer though.

Still seems like someone should know how to mess with the coding I provided above to get the number rounded correctly and show in bold and the numbers displayed in column form.

HELP!

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3893 posted 11:52 am on Jun 18, 2005 (gmt 0)

Relax. To round a number to two decimals: use the toFixed() method. E.g.:


var a = 10.302222
if (a.toFixed) { // condition to select modern browsers
a = a.toFixed(2); // 10.30 (2 is the required number of decimals)
} else {
a = Math.round(a*100)/100; // less perfect: will result in 10.3
}

usavetele

10+ Year Member



 
Msg#: 3893 posted 6:43 am on Jun 19, 2005 (gmt 0)

THANKS RonPK!

Needless to say, I'm new to javascript. I'm confused what "a" woudl be for my coding as listed in first postin this thread. I tried "USD" but that didn't work.

Thanks againg for your help!

usavetele

10+ Year Member



 
Msg#: 3893 posted 2:44 am on Jun 21, 2005 (gmt 0)

Help please. What would be "a"?

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3893 posted 8:02 am on Jun 21, 2005 (gmt 0)

Just insert the code after the line

var USD = EurToUSD(EUR, ExchRate);

and replace 'a' by 'USD'.

About your other questions: "and show in bold and the numbers displayed in column form." That's basic HTML: <b> or <span style="font-weight: bold;"> for bold, and a <table> to get things in nice rows and columns.

usavetele

10+ Year Member



 
Msg#: 3893 posted 4:20 am on Jun 24, 2005 (gmt 0)

I've found a better javscript code for converting currencies (see below). I'm very familiar with adding the <b> </b> to HTML coding, but have no clue where to add it to javascript coding. How do I do this? Also, how and where do I add "$" to the javascript coding so it before the USD amt. displayed? As for the number rounding coding listed above, would it still be the same coding for the following code?:

add before </head>:
<SCRIPT LANGUAGE="JavaScript">
exchRate = 1.20379;
function getUSD(price) {
document.write(price * exchRate);
}
</SCRIPT>

add in body:
<script type="text/javascript"> getUSD('42.99'); </script>

The above coding works great for converting currencies. I just need to know how to format the numbers to 2 decimal places, add the "$" in front of the USD amt. displayed and how to make it bold.

Please provide me very specific coding since I'm very green at javascript.

THANK YOUUUUUUUUUUUUUUUUUU! :)

usavetele

10+ Year Member



 
Msg#: 3893 posted 3:46 am on Jun 25, 2005 (gmt 0)

Hi guys! Sure would appreciate your help!

THANKS!

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3893 posted 11:42 am on Jun 25, 2005 (gmt 0)

Please provide me very specific coding since I'm very green at javascript.

I suppose members aren't flocking in because what you're asking is very basic Javascript. Any tutorial will tell you all about things like string concatenation.

I just need to know how to format the numbers to 2 decimal places, add the "$" in front of the USD amt. displayed and how to make it bold.

<script type="text/javascript">  
var exchRate = 1.20379;
function getUSD(price) {
var USD = price * exchRate;
if (USD.toFixed) { // check whether the browser supports that method
USD = USD.toFixed(2); // (2 is the required number of decimals)
} else {
USD = Math.round(USD*100)/100; // less perfect for older browsers
}
USD = '<b>$' + USD + '<\/b>'; // concatenation. escape the slash after the <
document.write(USD); // write the result
}
</script>

usavetele

10+ Year Member



 
Msg#: 3893 posted 1:51 am on Jun 27, 2005 (gmt 0)

Thanks RonPK!

I've found lots of tutorials, but since I nothing about Javascript, I couldn't figure out how to put the coding together.

THANK YOU SO MUCH FOR YOUR HELP! The coding works wonderfully!

usavetele

10+ Year Member



 
Msg#: 3893 posted 5:14 am on Jul 10, 2005 (gmt 0)

I have another question. What would be the coding for multiple currency conversions on the same web page? I thought it would be as easy as changing the "USD" to GBP" in the coding, but this doesn't work at all.

Thanks in advance for your help.

usavetele

10+ Year Member



 
Msg#: 3893 posted 3:17 am on Jul 11, 2005 (gmt 0)

So if I use the follow codes on the same page it only changes the currency for both prices based on the LAST code listed here:

How do I use this code to convert more than one currency on a web page?

<script type="text/javascript"> var exchRate = 1.20379; function getUSD(price) { var USD = price * exchRate; if (USD.toFixed) { // check whether the browser supports that method USD = USD.toFixed(2); // (2 is the required number of decimals) } else { USD = Math.round(USD*100)/100; // less perfect for older browsers } USD = '<b>$' + USD + '<\/b>'; // concatenation. escape the slash after the < document.write(USD); // write the result } </script>

<script type="text/javascript"> var exchRate = 0.68459; function getGBP(price) { var GBP = price * exchRate; if (GBP.toFixed) { // check whether the browser supports that method GBP = GBP.toFixed(2); // (2 is the required number of decimals) } else { GBP = Math.round(USD*100)/100; // less perfect for older browsers } GBP = '<b>$' + GBP + '<\/b>'; // concatenation. escape the slash after the < document.write(GBP); // write the result } </script>

Hope this makes sense! THANKS!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved