title: Simplest way of getting the number of decimals in a number in JavaScript
body: <p>Is there a better way of figuring out the number of decimals on a number than in my example?</p>
  
  <pre><code>var nbr = 37.435.45;
  var decimals = (nbr!=Math.floor(nbr))?(nbr.toString()).split('.')[1].length:0;
  </code></pre>
  
  <p>By better I mean faster to execute and/or using a native JavaScript function, ie. something like nbr.getDecimals().</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <p>After modifying series0ne answer, the fastest way I could manage is:</p>
  
  <pre><code>var val = 37.435345;
  var countDecimals = function(value) {
      if (Math.floor(value) !== value)
          return value.toString().split(".")[1].length || 0;
      return 0;
  }
  countDecimals(val);
  </code></pre>
  
  <p>Speed test: <a href="http://jsperf.com/checkdecimals" rel="noreferrer">http://jsperf.com/checkdecimals</a></p>