Currency code help

R

Rash33d

Hi there! could som1 please help me out? i need toknow if there's
something wrong with this javascript code. The code is meant to give
the american dollar and european equivalent of a price. i.e when i type
a price in pounds, it gives me the price in dollars and euros. Thanks
in advance


function fix(thenumber,noplaces){ // returns the number to n decimal
places
var oldnumber=thenumber;
thenumber=thenumber+"0000";
var decpos=thenumber.indexOf(".");
if (decpos==-1) return oldnumber+".00";
decpos=decpos+noplaces+1;
var endstring=thenumber.substring(0,decpos);
return endstring;
}



function convert_currency(){
//var
dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency.value);
//document.converter.converted.value=fix(dollarval*ConversionFactor(document.converter.targetcurrency.value),2);

var dollarval= document.form.gbp.value;
document.form.usd.value=fix(dollarval*1.85,2);
document.form.eur.value=fix(dollarval*1.46,2);

}


function convert_currency_spec(){
//var
dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency.value);
//document.converter.converted.value=fix(dollarval*ConversionFactor(document.converter.targetcurrency.value),2);

var dollarval= document.form.special_offer_original_gbp.value;
document.form.special_offer_original_usd.value=fix(dollarval*1.85,2);
document.form.special_offer_original_eur.value=fix(dollarval*1.46,2);

}
 
V

Vincent van Beveren

Hi there! could som1 please help me out? i need toknow if there's
something wrong with this javascript code. The code is meant to give
the american dollar and european equivalent of a price. i.e when i type
a price in pounds, it gives me the price in dollars and euros. Thanks
in advance

You might need to hint JavaScript a bit about the type of your
variables. The value of an input field is usually a String. Use
parseFloat(var) to explicitly convert a string to a floating point
value. Though JavaScript is weakly typed, it does need some help sometimes.

Good luck,
Vincent
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 14 Jul 2006 05:36:29 remote, seen in
function fix(thenumber,noplaces){ // returns the number to n decimal
places
var oldnumber=thenumber;
thenumber=thenumber+"0000";
var decpos=thenumber.indexOf(".");
if (decpos==-1) return oldnumber+".00";
decpos=decpos+noplaces+1;
var endstring=thenumber.substring(0,decpos);
return endstring;
}

fix(1, 3) fails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top