提交 4e97ff4f authored 作者: Thomas Mueller's avatar Thomas Mueller

When casting from float or double to BigDecimal, the result was sometimes unexpected.

上级 049bd3fa
...@@ -606,14 +606,14 @@ public abstract class Value { ...@@ -606,14 +606,14 @@ public abstract class Value {
if (Double.isInfinite(d) || Double.isNaN(d)) { if (Double.isInfinite(d) || Double.isNaN(d)) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "" + d); throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "" + d);
} }
return ValueDecimal.get(new BigDecimal(d)); return ValueDecimal.get(BigDecimal.valueOf(d));
} }
case FLOAT: { case FLOAT: {
float f = getFloat(); float f = getFloat();
if (Float.isInfinite(f) || Float.isNaN(f)) { if (Float.isInfinite(f) || Float.isNaN(f)) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "" + f); throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "" + f);
} }
return ValueDecimal.get(new BigDecimal(f)); return ValueDecimal.get(new BigDecimal(Float.toString(f)));
} }
} }
break; break;
......
select cast(cast(0.1 as real) as decimal);
> 0.1;
select cast(cast(95605327.73 as float) as decimal);
> 95605327.73;
select timestampdiff(month, '2003-02-01','2003-05-01'); select timestampdiff(month, '2003-02-01','2003-05-01');
> 3; > 3;
select timestampdiff(YEAR,'2002-05-01','2001-01-01'); select timestampdiff(YEAR,'2002-05-01','2001-01-01');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论