jquery - Javascript - Leading zero to a number converting the number to some different number. not getting why this happening? -


a leading 0 number converting number unknown number format. example :

017 getting converted 15

037 getting converted 31

also found numbers having 8 0r 9 @ end remaining same example :

018 18

038 38

o59 59

one more thing found is

for each next range of 10 difference between converted value , actual value incremented 2

for example :

for range 00-09 difference 0 i.e value of 07 7, 04 4

for range 010-019 difference 2 value of 017 15, 013 11

for range 020-029 difference 4 value of 027 23, 021 17

and on..

here snipet test http://jsfiddle.net/rajubera/bxqhf/

i not getting why happening ?

please me how correct decimal number number having leading 0 ?

if there leading 0, converting octal (base 8) long valid number in base 8 (no numbers greater 7).

for example:

017 in base 8 1 * 8 + 7 = 15 037 in base 8 3 * 8 + 7 = 31

018 converted 18 because 018 isn't valid number in base 8

note behavior base number converted default can browser-specific, important specify base/radix when using parseint:

parseint("017",10) === 17

update based on comments:

parseint expects string first argument, so

parseint("012",10) === 12


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -