Skip to content

Decimal rounding uses different rounding mode #7044

@SergeyMirvoda

Description

@SergeyMirvoda

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 TABLE statements for all tables involved

  • Sample data for all these tables, use clickhouse-obfuscator if necessary

  • Queries to run that lead to unexpected result
    изображение

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 descending

Expected 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-decimalDecimal datatype semantics, arithmetic, casting, serialization.comp-documentationDocumentation (docs, examples, READMEs).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions