title: javascript trunc() function
body: <p>I want to truncate a number in javascript, that means to cut away the decimal part:</p>
  <p><strong>trunc ( 2.6 ) == 2</strong></p>
  <p><strong>trunc (-2.6 ) == -2</strong></p>
  <hr />
  <p>After heavy benchmarking my answer is:</p>
  <pre><code> function trunc (n) {
      return ~~n;
   }
   
   // or  
  
   function trunc1 (n) {
      return n | 0;
   }
  </code></pre>