Numbers starting with 0
are Octal. So, 032 === 26
.
To convert it into Base-10/Decimal number use parseInt
with radix 10.
parseInt('032', 10) * 2; // 64
From MDN Docs:
If radix is undefined or 0 (or absent), JavaScript assumes the following:
- If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.
- If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
- If the input string begins with any other value, the radix is 10 (decimal).