[X]

parseInt On A Tiny Number

luljs still works

parseInt of a very small decimal returns 5.

In 2026: Still works. parseInt expects a string, so it converts the number first. A tiny value like 0.0000005 stringifies to "5e-7" in exponential form. parseInt reads the leading "5", stops at "e", and returns 5. parseInt was never meant for floats.

Where it came from: parseInt coerces its argument to a string first, and small numbers stringify to exponential form. MDN's parseInt page warns against using it on numbers. MDN

<script>
document.write('<p><code>String(0.0000005)</code> is <b>"' + String(0.0000005) + '"</b></p>');
document.write('<p><code>parseInt(0.0000005)</code> is <b>' + parseInt(0.0000005) + '</b></p>');
document.write('<p>The number stringifies to "5e-7", and parseInt reads just the "5".</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›