summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_math.result3
-rw-r--r--mysql-test/t/func_math.test5
-rw-r--r--sql/item_func.cc19
3 files changed, 15 insertions, 12 deletions
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result
index e4889289c18..c7674c57c8d 100644
--- a/mysql-test/r/func_math.result
+++ b/mysql-test/r/func_math.result
@@ -143,3 +143,6 @@ select format(col2,6) from t1 where col1=7;
format(col2,6)
1,234,567,890,123,456.123450
drop table t1;
+select round(150, 2);
+round(150, 2)
+150.00
diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test
index b21f38052b6..03057af6911 100644
--- a/mysql-test/t/func_math.test
+++ b/mysql-test/t/func_math.test
@@ -79,3 +79,8 @@ insert into t1 values(7,1234567890123456.12345);
select format(col2,6) from t1 where col1=7;
drop table t1;
+
+#
+# Bug #10083 (round doesn't increase decimals)
+#
+select round(150, 2);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 68292859504..c3fc537f04e 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1876,7 +1876,8 @@ void Item_func_round::fix_length_and_dec()
max_length= float_length(decimals);
break;
case INT_RESULT:
- if (truncate || (args[0]->decimal_precision() < DECIMAL_LONGLONG_DIGITS))
+ if ((decimals_to_set==0) &&
+ (truncate || (args[0]->decimal_precision() < DECIMAL_LONGLONG_DIGITS)))
{
/* Here we can keep INT_RESULT */
hybrid_type= INT_RESULT;
@@ -1890,18 +1891,12 @@ void Item_func_round::fix_length_and_dec()
hybrid_type= DECIMAL_RESULT;
int decimals_delta= args[0]->decimals - decimals_to_set;
int precision= args[0]->decimal_precision();
- if (decimals_delta > 0)
- {
- int length_increase= truncate ? 0:1;
- precision-= decimals_delta - length_increase;
- decimals= decimals_to_set;
- }
- else
- /* Decimals to set is bigger that the original scale */
- /* we keep original decimals value */
- decimals= args[0]->decimals;
+ int length_increase= ((decimals_delta <= 0) || truncate) ? 0:1;
+
+ precision-= decimals_delta - length_increase;
+ decimals= decimals_to_set;
max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ unsigned_flag);
break;
}
default: