Welcome to WebmasterWorld Guest from 54.166.54.215

Forum Moderators: open

Showing different currencies on product pages

then updating the exchange rate once a week

   
3:28 am on Jun 18, 2005 (gmt 0)

10+ Year Member



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>

3:32 am on Jun 18, 2005 (gmt 0)

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



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!
3:40 am on Jun 18, 2005 (gmt 0)

10+ Year Member



"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).

5:06 am on Jun 18, 2005 (gmt 0)

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



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).

5:13 am on Jun 18, 2005 (gmt 0)

10+ Year Member



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!

11:52 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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
}
6:43 am on Jun 19, 2005 (gmt 0)

10+ Year Member



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!

2:44 am on Jun 21, 2005 (gmt 0)

10+ Year Member



Help please. What would be "a"?
8:02 am on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

4:20 am on Jun 24, 2005 (gmt 0)

10+ Year Member



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! :)

3:46 am on Jun 25, 2005 (gmt 0)

10+ Year Member



Hi guys! Sure would appreciate your help!

THANKS!

11:42 am on Jun 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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>
1:51 am on Jun 27, 2005 (gmt 0)

10+ Year Member



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!

5:14 am on Jul 10, 2005 (gmt 0)

10+ Year Member



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.

3:17 am on Jul 11, 2005 (gmt 0)

10+ Year Member



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!

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month