>> Be very careful using the + operator this way.
>>  +"32px" returns NaN
>>  parseInt("32px") returns 32

> True, but in this case you aren't really type-converting to a number,
> you're actually wanting to extract a number from a string.

Yeah, I just saw the gleam in Jörn's eye and knew he was thinking about
changing the parseInt/parseFloat to + in jQuery core. There are a lot of
places where strings with trailing units are converted to numbers, and +
isn't appropriate there.

> And one of the main reasons to recommend + over parseInt() 
> is because many people try to do parseInt('09') and get the
> wrong result and can't figure out why. In this case, +"09"
> works as expected.

My favorites are the pathological inputs like "08E1" that give you 0 from
parseInt and 800 from +/parseFloat.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to