Skip to content

I would like to round rather than truncate when casting f64 to decimal #2997

Closed

Description

@andygrove

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

If I convert 0.06999999 to a decimal with scale 2 I would like to get 0.07 rather than 0.06

    #[test]
    #[cfg(not(feature = "force_validate"))]
    fn test_cast_f64_to_decimal128() {
        let decimal_type = DataType::Decimal128(18, 2);
        let array = Float64Array::from(vec![
            Some(0.0699999999),
        ]);
        let array = Arc::new(array) as ArrayRef;
        generate_cast_test_case!(
            &array,
            Decimal128Array,
            &decimal_type,
            vec![
                Some(7_i128),
            ]
        );
    }

This fails with:

Left:  6
Right: 7

Describe the solution you'd like

Provide an option for round vs truncate?
Default to round?

Describe alternatives you've considered

Additional context

Activity

  1. andygrove commented on Nov 2, 2022

    @andygrove
    MemberAuthor
  2. changed the title [-]I would like to round rather than trucate when casting f64 to decimal[/-] [+]I would like to round rather than truncate when casting f64 to decimal[/+] on Nov 2, 2022
  3. alamb commented on Nov 11, 2022

    @alamb
    Contributor

    label_issue.py automatically added labels {'arrow'} from #3000

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

    arrowChanges to the arrow crateenhancementNew feature/addition

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions