[Javascript] (no subject)

Mark Wonsil wonsil at 4m-ent.com
Wed Nov 2 12:19:32 CST 2005


> 
> kpp = parseFloat(kpp);
> kph = parseFloat(kph);
> if(!isNaN(kpp) &&!isNaN(kph) )
> {
> 	ktot = kpp + kph;
> }
> alert("passed here, with value of " + ktot + ".")
> If(ktot>'8')

It's a type issue, very common in JavaScript. Ktot is a float but '8' is a
character. Try:

If (ktot > 8f)

Or

If (ktot > parseFloat('8'))

BTW, comparing floats can be tricky. Do you care if the total is 8.00001 or
8.000000003232? Those will be greater than 8.0. What I normally do is
subtract the two numbers, take the absolute value and check to see if the
difference is within my tolerance:

If (abs(ktot - 8.0f)) < 0.0001

Mark W.




More information about the Javascript mailing list