Question: I try to convert a number with leading zero. JavaScript interpret the number with leading zero as octal number. But I would like to convert the number to string as decimal number and preserve the leading zero. Any idea?

```
<!DOCTYPE html>
 <html>
 <body>

<p>Click the button to display the formatted number.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
    function myFunction() {
    var num = 015;

    var n = Number(num).toString();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

```

Answer: 
try below code

```
function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }
    document.getElementById("demo").innerHTML = pad(15, 4);

```

output:
0015
The parseInt() and parseFloat() functions parse a string until they reach a character that isn't valid for the specified number format, then return the number parsed up to that point. However the "+" operator simply converts the string to NaN if there is an invalid character contained within it. Just try parsing the string "10.2abc" with each method by yourself in the console and you'll understand the differences better.

+"42"; // 42  

+"010"; // 10  

+"0x10"; // 16  

a = "0042";  

alert(typeof +a); // number  

alert(+a); // 42