My Profile Photo

Matthias Lischka

S O F T W A R E   D E V E L O P M E N T

Rounding -0.5 is easy, right?

What is -0.5 “default” rounded?

Think about this before you continue reading!

Well, we had some fun today at work with this question and even more fun when we put our preferred programming languages to the test. Behold the results.

Input 0.6 0.5 0.4 -0.4 -0.5 -0.6  
C# 1 0 0 0 0 -1 Math.Round(-0.5)
Java 1 1 0 0 0 -1 Math.round(-0.5)
Python 1 0 0 0 0 -1 round(-0.5)
C 1 1 0 -0 -1 -1 round(-0.5)
Go 1 1 0 -0 -1 -1 math.Round(-0.5)
PHP 1 1 0 -0 -1 -1 round(-0.5)
JavaScript 1 1 0 -0 -0 -1 Math.round(-0.5)
Excel 1 1 0 0 -1 -1 ROUND(-0.5;0)

I like -0. Did honestly not know that.

surprise