Forum Moderators: open
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>
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).
1.5 us / 1.9 ca *
*Based on avg us/ca rates, (url here).
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!
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.
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! :)
Please provide me very specific coding since I'm very green at javascript.
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>
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!