Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>var intvalue = Math.floor( floatvalue ); var intvalue = Math.ceil( floatvalue ); var intvalue = Math.round( floatvalue ); // `Math.trunc` was added in ECMAScript 6 var intvalue = Math.trunc( floatvalue ); </code></pre> <p><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math" rel="noreferrer">Math object reference</a></p> <hr> <h3>Examples</h3> <strong>Positive</strong> <pre><code>value = 5.5 Math.floor(value) // 5 Math.ceil(value) // 6 Math.round(value) // 6 Math.trunc(value) // 5 parseInt(value) // 5 ~~value // 5 value | 0 // 5 value &gt;&gt; 0 // 5 value &gt;&gt;&gt; 0 // 5 value - value % 1 // 5 </code></pre> <strong>Negative</strong> <pre><code>value = -5.5 Math.floor(value) // -6 Math.ceil(value) // -5 Math.round(value) // -5 Math.trunc(value) // -5 parseInt(value) // -5 value | 0 // -5 ~~value // -5 value &gt;&gt; 0 // -5 value &gt;&gt;&gt; 0 // 4294967291 value - value % 1 // -5 </code></pre> <strong>Positive - Larger numbers</strong> <pre><code>value = Number.MAX_SAFE_INTEGER/10 // 900719925474099.1 Math.floor(value) // 900719925474099 Math.ceil(value) // 900719925474100 Math.round(value) // 900719925474099 Math.trunc(value) // 900719925474099 parseInt(value) // 900719925474099 value | 0 // 858993459 ~~value // 858993459 value &gt;&gt; 0 // 858993459 value &gt;&gt;&gt; 0 // 858993459 value - value % 1 // 900719925474099 </code></pre> <strong>Negative - Larger numbers</strong> <pre><code>value = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1 Math.floor(value) // -900719925474100 Math.ceil(value) // -900719925474099 Math.round(value) // -900719925474099 Math.trunc(value) // -900719925474099 parseInt(value) // -900719925474099 value | 0 // -858993459 ~~value // -858993459 value &gt;&gt; 0 // -858993459 value &gt;&gt;&gt; 0 // 3435973837 value - value % 1 // -900719925474099 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload