Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andygrove opened this issue Nov 2, 2022 · 2 comments · Fixed by #3000
Closed

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

andygrove opened this issue Nov 2, 2022 · 2 comments · Fixed by #3000
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@andygrove
Copy link
Member

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

@andygrove andygrove added the enhancement Any new improvement worthy of a entry in the changelog label Nov 2, 2022
@andygrove
Copy link
Member Author

@liukun4515 @viirya fyi

@andygrove andygrove 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 Nov 2, 2022
@alamb
Copy link
Contributor

alamb commented Nov 11, 2022

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

@alamb alamb added the arrow Changes to the arrow crate label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants