tsql
tsql copied to clipboard
Describe `ROUND(x)` WTFs
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
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