October 15, 2000 - Converting Zero-Leading Strings to Integers | WebReference

October 15, 2000 - Converting Zero-Leading Strings to Integers

Yehuda Shiran October 15, 2000
Converting Zero-Leading Strings to Integers
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

When you convert a zero-leading string to an integer, you get the most significant zero. For example:

parseInt("009");

yields zero (0). You can get around it by specifying a radix of 10. For example:

parseInt("009", 10);

yields 9. Specifying any other radix which is smaller than 10 will yield zero (0). Try it:

This tip has been contributed by KP.