Bug Javascript Function parseInt

Not so long ago I encountered a problem with the parseInt JavaScript function. In some cases the parseInt returns an incorrect value. For example, parseInt("08") results in 0 instead of 8 and parseInt("09") also results in 0 instead of 9.
Apparently the reason for this is because the zero in front is trying to tell the browser that this is an octal number, and "08" and "09" are not valid octal numbers.
With parseFloat I didn't have the problem. So to "fix" the problem, I used the following: parseInt(parseFloat("string value"))

Please note that this "bug" only happens when the value being checked is a string and the string starts with a leading zero.

Kevin Dosseray

Comments

Popular posts from this blog

Scribe and Excel Data Ranges

Scribe MVP!