title: Convert octal or decimal number to decimal string
body: <p>I have input variables that are of type <code>number</code> and can start with any digit, including 0. <br />
  I want to convert the input numbers to a (decimal) string but have trouble doing so.</p>
  <p>Using the <code>String(number)</code> function works if the number does not start with a 0, but fails when it does since it perceives it as an octal number. <br />
  Using the <code>number.toString()</code> function works if the number starts with a 0, but fails when it does not. This drops the starting 0 by the way, which is not a problem for my further analysis.</p>
  <p><strong>Example</strong></p>
  <pre><code>var num1 = 0123456;
  var num2 = 123456;
  
  var s1 = String(num1); // returns &quot;42798&quot;  -&gt; wanted &quot;0123456&quot;
  var s2 = String(num2); // returns &quot;123456&quot; -&gt; correct
  
  var s1 = num1.toString(8); // returns &quot;123456&quot; -&gt; correct
  var s2 = num2.toString(8); // returns &quot;361100&quot; -&gt; wanted &quot;123456&quot;
  </code></pre>
  <p>I can not find any alternatives to these functions. I have also tried to come up with a way to identify whether the first digit is a 0, but I could not find any effective ways.</p>
  <p>Any ideas?</p>