Skip to content

Round error when casting float to decimal #4071

Closed

Description

@andygrove

Describe the bug

Spark

scala> spark.sql("select cast(0.06+0.01 as decimal(18,2))").show
+------------------------------------+
|CAST((0.06 + 0.01) AS DECIMAL(18,2))|
+------------------------------------+
|                                0.07|
+------------------------------------+

DataFusion

❯ select cast(0.06+0.01 as decimal(18,2));
+-------------------------------+
| Float64(0.06) + Float64(0.01) |
+-------------------------------+
| 0.06                          |
+-------------------------------+

To Reproduce
See above

Expected behavior

Additional context
Discovered as part of #4024

Activity

  1. added this to the 14.0.0 milestone on Nov 1, 2022
  2. changed the title [-]Inconsistent behavior with literal value versus expression in filter[/-] [+]Round error when casting float to decimal[/+] on Nov 2, 2022
  3. andygrove commented on Nov 2, 2022

    @andygrove
    MemberAuthor

    filed related issue in arrow-rs: apache/arrow-rs#2997

  4. modified the milestones: 14.0.0, 15.0.0 on Nov 2, 2022
  5. tustvold commented on Nov 15, 2022

    @tustvold
    Contributor

    Fixed by #4199

    ❯ select cast(0.06+0.01 as decimal(18,2));
    +-------------------------------+
    | Float64(0.06) + Float64(0.01) |
    +-------------------------------+
    | 0.07                          |
    +-------------------------------+
    1 row in set. Query took 0.008 seconds.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions