-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Decimal rounding uses different rounding mode #7044
Description
Describe the bug or unexpected behaviour
This help page precisely states that round function uses Banker's rounding.
But this statement doesn't holds for decimal type. We believe (did not checked the sources), that decimal rounding uses IEEE 754 away from zero mode.
How to reproduce
-
Which ClickHouse server version to use
19.11.3.11 -
Which interface to use, if matters
doesn't matter (SQL query in DataGrip) -
Non-default settings, if any
no -
CREATE TABLEstatements for all tables involved -
Sample data for all these tables, use clickhouse-obfuscator if necessary
select 3.5 as v, round(toDecimal32(v,2)) as round_dec, round(v) as round_float
union all
select 2.5 as v, round(toDecimal32(v,2)), round(v)
union all
select 1.5 as v, round(toDecimal32(v,2)), round(v)
union all
select 0.5 as v, round(toDecimal32(v,2)), round(v)
union all
select -0.5 as v, round(toDecimal32(v,2)), round(v)
order by 1 descendingExpected behavior
Actually the decimal behavior is what we need, we only want to sure is it bug in documentation or bug in decimal code?
Additional context
Is it good to have two different rounding schemes?
Can we have some arguments in round function?
see also #1211
