ParseInt bug

Discussion of actual or possible Photoshop Scripting Bugs, Anomalies and Documentation Errors

Moderators: Tom, Kukurykus

csuebele

ParseInt bug

Post 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))
xbytor

ParseInt bug

Post 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.
csuebele

ParseInt bug

Post by csuebele »

Thanks, X, I need to learn these things better. I should have been using Number() instead.