title: Get float's length in JavaScript
body: <p>I'm trying to get the length of a <code>float</code> in JavaScript, but I I can't make it work as a <code>string</code>:</p>
  
  <pre><code>var length = ((x + '').toString().length;
  </code></pre>
  
  <p>because, <code>undefined</code> is a very regular and possible value of the variable, so I end up getting the length of  <code>"undefined"</code>...</p>
  
  <p>I see various possible solutions:</p>
  
  <ul>
  <li><p>Allocate every <code>float</code>'s digit in a array with <code>number.isFloat()</code> and count arrays's length.</p></li>
  <li><p>By finding an mathematical solution alike: <code>(Math.log10((newValue ^ (newValue &gt;&gt; 31)) - (newValue &gt;&gt; 31)) | 0) + 1</code>, but applied to <code>float</code> values and not only integers.</p></li>
  <li><p>Some dummy function that loops every digit.</p></li>
  <li><p>Use a specific math library (<a href="http://mathjs.org/" rel="nofollow noreferrer">http://mathjs.org/</a>), which seems to me like the best solution, since I am not being able to find any working function that will perform this task without damaging the performance. </p></li>
  </ul>