From 5cd06117f0610ed6cc0b746c3b467da263fc9aaf Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 3 Jun 2025 09:47:38 +0200 Subject: [PATCH] fix: update rounding strategy --- core/expression/src/functions/internal.rs | 7 +++++-- core/expression/tests/data/standard.csv | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/expression/src/functions/internal.rs b/core/expression/src/functions/internal.rs index 387ae126..0e467ad2 100644 --- a/core/expression/src/functions/internal.rs +++ b/core/expression/src/functions/internal.rs @@ -313,7 +313,7 @@ pub(crate) mod imp { #[cfg(feature = "regex-lite")] use regex_lite::Regex; use rust_decimal::prelude::{FromPrimitive, ToPrimitive}; - use rust_decimal::Decimal; + use rust_decimal::{Decimal, RoundingStrategy}; use rust_decimal_macros::dec; use std::collections::BTreeMap; use std::rc::Rc; @@ -473,7 +473,10 @@ pub(crate) mod imp { .transpose()? .unwrap_or(0); - Ok(V::Number(a.round_dp(dp))) + Ok(V::Number(a.round_dp_with_strategy( + dp, + RoundingStrategy::MidpointAwayFromZero, + ))) } pub fn trunc(args: Arguments) -> anyhow::Result { diff --git a/core/expression/tests/data/standard.csv b/core/expression/tests/data/standard.csv index 6f03b62c..99ff24d9 100644 --- a/core/expression/tests/data/standard.csv +++ b/core/expression/tests/data/standard.csv @@ -441,6 +441,10 @@ round(7.6);; 8 round(-7.4);; -7 round(-7.5);; -8 round(-7.6);; -8 +round(0.5);;1 +round(-0.5);;-1 +round(1.5);;2 +round(-1.5);;-2 round(7.444, 0);; 7 round(7.444, 1);; 7.4