[X]

Math.round Rounds Up

luljs still works

Round a score of 2.5 and get 3, but round -2.5 and get -2.

In 2026: Still works. Math.round always rounds a half toward positive infinity, not away from zero. So 2.5 goes up to 3 and 0.5 goes up to 1, but -2.5 goes up to -2 and -0.5 goes up to -0. Rounding a column of negative halves quietly biases them one way.

Where it came from: Math.round rounds halves toward positive infinity, documented on MDN, which is why negative halves round the opposite way to positive ones. MDN

<script>
document.write('<p><code>Math.round(2.5)</code> is <b>' + Math.round(2.5) + '</b>, <code>Math.round(-2.5)</code> is <b>' + Math.round(-2.5) + '</b></p>');
document.write('<p><code>Math.round(0.5)</code> is <b>' + Math.round(0.5) + '</b>, <code>Math.round(-0.5)</code> is <b>' + Math.round(-0.5) + '</b></p>');
document.write('<p>Halves always round toward +Infinity, not away from zero.</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›