Commit 98c2ec75 authored by unknown's avatar unknown

Fix for bug #8482 (Incorrect rounding)


mysql-test/r/type_newdecimal.result:
  test result fixed
mysql-test/t/type_newdecimal.test:
  test case added
strings/decimal.c:
  in round(999.9, 0) case we have to increase intg
parent 0537106b
......@@ -896,6 +896,14 @@ create table t1( d1 decimal(18) unsigned, d2 decimal(20) unsigned, d3 decimal (2
insert into t1 values(1,-1,-1);
ERROR 22003: Out of range value adjusted for column 'd2' at row 1
drop table t1;
create table t1 (col1 decimal(5,2), col2 numeric(5,2));
insert into t1 values (999.999,999.999);
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
insert into t1 values (-999.999,-999.999);
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
select * from t1;
col1 col2
drop table t1;
set sql_mode='';
set @sav_dpi= @@div_precision_increment;
set @@div_precision_increment=15;
......
......@@ -934,6 +934,13 @@ create table t1( d1 decimal(18) unsigned, d2 decimal(20) unsigned, d3 decimal (2
--error 1264
insert into t1 values(1,-1,-1);
drop table t1;
create table t1 (col1 decimal(5,2), col2 numeric(5,2));
--error 1264
insert into t1 values (999.999,999.999);
--error 1264
insert into t1 values (-999.999,-999.999);
select * from t1;
drop table t1;
set sql_mode='';
#
......
......@@ -1546,6 +1546,14 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
*buf1=1;
to->intg++;
}
/* Here we check 999.9 -> 1000 case when we need to increase intg */
else
{
int first_dig= to->intg % DIG_PER_DEC1;
/* first_dig==0 should be handled above in the 'if' */
if (first_dig && (*buf1 >= powers10[first_dig]))
to->intg++;
}
}
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment