This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 6c05f7a8c232ad572382585ca86e3573d8004e3d
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 24 09:18:36 2026 +0800

    branch-4.1: [fix](function) Round Decimal values with zero decimal places 
#68010 (#68412)
    
    Cherry-picked from #68010
    
    Co-authored-by: Mryange <[email protected]>
---
 be/src/exprs/function/function_string_format.h                   | 2 +-
 .../query_p0/sql_functions/math_functions/test_format_round.out  | 9 ++++++++-
 .../sql_functions/math_functions/test_format_round.groovy        | 9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/be/src/exprs/function/function_string_format.h 
b/be/src/exprs/function/function_string_format.h
index c5837b37500..a65f0768826 100644
--- a/be/src/exprs/function/function_string_format.h
+++ b/be/src/exprs/function/function_string_format.h
@@ -268,7 +268,7 @@ StringRef do_format_round(FunctionContext* context, UInt32 
scale, T int_value, T
     const bool is_negative = int_value < 0 || frac_value < 0;
 
     // do round to frac_part based on decimal_places
-    if (scale > decimal_places && decimal_places > 0) {
+    if (static_cast<Int32>(scale) > decimal_places) {
         DCHECK(scale <= 38);
         // do rounding, so we need to reserve decimal_places + 1 digits
         auto multiplier =
diff --git 
a/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
 
b/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
index 9a5e2caa452..1d91fdc4869 100644
--- 
a/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
+++ 
b/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
@@ -47,8 +47,15 @@
 123,456.123457
 34.123457
 
+-- !format_round_73 --
+2      -2      1       -1
+
+-- !format_round_74 --
+123,456
+34
+
 -- !format_round_14 --
-9,876
+9,877
 
 -- !format_round_15 --
 0.0000001
diff --git 
a/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
 
b/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
index 9f179c48759..5304e617bcc 100644
--- 
a/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
@@ -56,6 +56,13 @@ suite("test_format_round", "p0") {
     order_qt_format_round_10 """ select format_round(largeint_col, 6) from 
test_format_round order by user_id"""
     order_qt_format_round_12 """ select format_round(double_col, 6) from 
test_format_round order by user_id"""
     order_qt_format_round_13 """ select format_round(decimal_col, 6) from 
test_format_round order by user_id"""
+    order_qt_format_round_73 """
+        select format_round(cast(1.9 as decimal(9, 1)), 0),
+                format_round(cast(-1.9 as decimal(9, 1)), 0),
+                format_round(cast(1.4 as decimal(9, 1)), 0),
+                format_round(cast(-1.4 as decimal(9, 1)), 0);
+    """
+    order_qt_format_round_74 """ select format_round(decimal_col, 0) from 
test_format_round order by user_id"""
 
     test {
         sql """select format_round(1234567.8910, -1) """
@@ -125,4 +132,4 @@ suite("test_format_round", "p0") {
     order_qt_format_round_69 """ SELECT format_round(2.2250738585072014E-308, 
324) AS result; """
     order_qt_format_round_70 """ SELECT 
format_round(0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
 0) AS result; """
     order_qt_format_round_71 """ SELECT 
format_round(0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
 10) AS result; """
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to