tsql icon indicating copy to clipboard operation
tsql copied to clipboard

Describe `ROUND(x)` WTFs

Open AnyhowStep opened this issue 5 years ago • 1 comments
trafficstars

SELECT
ROUND(0.5e0),
ROUND(-0.5e0)

Where the numbers are double precision data types.

It's 0 and 0 on PostgreSQL.

It's 1 and -1 on SQLite

It's 1 and 0 on JS

It's 0 and 0 on MySQL


But if 0.5 and -0.5 is a DECIMAL on MySQL, then the answer is 1 and -1

But if 0.5 and -0.5 is a DECIMAL on PostgreSQL, then the answer is 1 and -1

AnyhowStep avatar Feb 18 '20 22:02 AnyhowStep

Well, not really a WTF. It's just that there are so many different ways to round numbers.

https://en.wikipedia.org/wiki/Rounding#Round_half_to_even

AnyhowStep avatar Feb 18 '20 22:02 AnyhowStep