Skip to main content

Command Palette

Search for a command to run...

Dealing with integer number leading with 0(s) in JavaScript

Published
1 min read

parseInt(012, 10) // 10 parseInt(05, 10) // 5

Interesting, huh? That’s because js would treat number leading with zero(s) as octal numeral, so we need to convert it into decimal number and treat it as string. So here is my solution:

// num = 0120
var result = parseInt(num, 10).toString(8)
// result = '120'
7 views

More from this blog

Al's blog

21 posts