Page 1 of 1

ParseInt bug

Posted: Wed May 01, 2013 3:41 pm
by csuebele
I'm not sure if this is an extendscript bug or an OS bug. If you run the following script, you get a result of "0" rather than "NaN", which should be the result.

Code: Select all#target photoshop
var t = '0a5'
alert(parseInt(t))

ParseInt bug

Posted: Wed May 01, 2013 7:17 pm
by xbytor
That behavior is correct. parseInt will use whatever digits it finds at the beginning of the string to construct an int. If the string does not start with a digit, it will return NaN. If you want to force parse the entire string, use Number(t), which would return NaN in this case.

ParseInt bug

Posted: Wed May 01, 2013 7:57 pm
by csuebele
Thanks, X, I need to learn these things better. I should have been using Number() instead.