Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] (no subject)


  • From: wonsil at 4m-ent.com (Mark Wonsil)
  • Subject: [Javascript] (no subject)
  • Date: Wed Nov 2 12:20:14 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.