ParseInt bug

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

Moderators: xbytor, DavideBarranca, Paul MR

csuebele

ParseInt bug

Postby csuebele » Wed May 01, 2013 3:41 pm

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

Postby xbytor » Wed May 01, 2013 7:17 pm

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

Postby csuebele » Wed May 01, 2013 7:57 pm

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


Return to “Photoshop Scripting Bugs and Anomalies”

Who is online

Users browsing this forum: No registered users and 1 guest