Commit fb832641 authored by unknown's avatar unknown

Fix for bug #14268 (Bad FLOAT->DECIMAL conversion)


mysql-test/r/type_newdecimal.result:
  test result updated
mysql-test/t/type_newdecimal.test:
  test case added
strings/decimal.c:
  i think that gives the proper precision
parent d8fa9819
This diff is collapsed.
......@@ -1050,3 +1050,38 @@ select cast(@non_existing_user_var/2 as DECIMAL);
#
--error 1427
create table t (d decimal(0,10));
#
# Bug #14268 (bad FLOAT->DECIMAL conversion)
#
CREATE TABLE t1 (
my_float FLOAT,
my_double DOUBLE,
my_varchar VARCHAR(50),
my_decimal DECIMAL(65,30)
);
SHOW CREATE TABLE t1;
let $max_power= 32;
while ($max_power)
{
eval INSERT INTO t1 SET my_float = 1.175494345e-$max_power,
my_double = 1.175494345e-$max_power,
my_varchar = '1.175494345e-$max_power';
dec $max_power;
}
SELECT my_float, my_double, my_varchar FROM t1;
SELECT CAST(my_float AS DECIMAL(65,30)), my_float FROM t1;
SELECT CAST(my_double AS DECIMAL(65,30)), my_double FROM t1;
SELECT CAST(my_varchar AS DECIMAL(65,30)), my_varchar FROM t1;
UPDATE t1 SET my_decimal = my_float;
SELECT my_decimal, my_float FROM t1;
UPDATE t1 SET my_decimal = my_double;
SELECT my_decimal, my_double FROM t1;
UPDATE t1 SET my_decimal = my_varchar;
SELECT my_decimal, my_varchar FROM t1;
DROP TABLE t1;
......@@ -973,7 +973,7 @@ int double2decimal(double from, decimal_t *to)
{
/* TODO: fix it, when we'll have dtoa */
char s[400], *end;
sprintf(s, "%f", from);
sprintf(s, "%.16G", from);
end= strend(s);
return string2decimal(s, to, &end);
}
......
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