Article ID: 191434 - Last Review: March 3, 2005 - Revision: 2.1 PRB: Parseint Returns 0 for Some Strings with Leading ZerosThis article was previously published under Q191434 On This PageSYMPTOMS
When a string value that contains leading zeros is passed to the parseInt()
JScript function, parseInt will return 0 for "08" and "09".
CAUSE
In JavaScript placing a leading 0 in front of a number designates that
number as octal. In octal, there is no 08 or 09. Therefore, these numbers
are interpreted as 0.
RESOLUTION
You must remove the leading zeros before calling parseInt. Here is the code
for the workaround:
STATUS
This behavior is by design.
MORE INFORMATIONSteps to Reproduce BehaviorThe following Web page demonstrates this problem. This Web page contains a text box. When focus is shifted away from the edit box by pressing the TAB key, the parseInt() function is called with the value that was entered into the text box. The value returned from parseInt() is then displayed in an alert box. If you enter "08" or "09" into the text box, parseInt() returns a value of 0.APPLIES TO
| Article Translations
|

Back to the top
