Home › JavaScript Tutorial › JS numbers
JS numbers
Integers, decimals and conversion.
All numbers are 64-bit floats, so 0.1+0.2 is not exactly 0.3. Use toFixed, parseInt, parseFloat, Number() and check isNaN.
Example code
<pre id='o'></pre>
<script>
o.textContent=[0.1+0.2,(0.1+0.2).toFixed(2),parseInt('42px'),Number('abc'),isNaN('abc'),(1234.5).toLocaleString()].join('\n');
</script>