提交 9f9e251c authored 作者: Thomas Mueller's avatar Thomas Mueller

ROUND(..) now also works with just one parameter.

上级 ae3bd0a3
......@@ -2660,9 +2660,9 @@ RANDOM_UUID()
"
"Functions (Numeric)","ROUND","
ROUND(numeric, digitsInt)
ROUND(numeric [, digitsInt])
","
Rounds to a number of digits.
Rounds to a number of digits, or to the nearest long if the number of digits if not set.
This method returns a double.
","
ROUND(VALUE, 2)
......
......@@ -189,7 +189,7 @@ public class Function extends Expression implements FunctionCall {
// RAND with one argument: seed the random generator
addFunctionNotDeterministic("RAND", RAND, VAR_ARGS, Value.DOUBLE);
addFunctionNotDeterministic("RANDOM", RAND, VAR_ARGS, Value.DOUBLE);
addFunction("ROUND", ROUND, 2, Value.DOUBLE);
addFunction("ROUND", ROUND, VAR_ARGS, Value.DOUBLE);
addFunction("ROUNDMAGIC", ROUNDMAGIC, 1, Value.DOUBLE);
addFunction("SIGN", SIGN, 1, Value.INT);
addFunction("SIN", SIN, 1, Value.DOUBLE);
......@@ -925,7 +925,7 @@ public class Function extends Expression implements FunctionCall {
result = ValueDouble.get(Math.pow(v0.getDouble(), v1.getDouble()));
break;
case ROUND: {
double f = Math.pow(10., v1.getDouble());
double f = v1 == null ? 1. : Math.pow(10., v1.getDouble());
result = ValueDouble.get(Math.round(v0.getDouble() * f) / f);
break;
}
......@@ -1595,6 +1595,7 @@ public class Function extends Expression implements FunctionCall {
case RTRIM:
case TRIM:
case FILE_READ:
case ROUND:
min = 1;
max = 2;
break;
......
......@@ -9024,6 +9024,12 @@ select round(null, null) en, round(10.49, 0) e10, round(10.05, 1) e101 from test
> null 10.0 10.1
> rows: 1
select round(null) en, round(0.6, null) en2, round(1.05) e1, round(-1.51) em2 from test;
> EN EN2 E1 EM2
> ---- ---- --- ----
> null null 1.0 -2.0
> rows: 1
select roundmagic(null) en, roundmagic(cast(3.11 as double) - 3.1) e001, roundmagic(3.11-3.1-0.01) e000, roundmagic(2000000000000) e20x from test;
> EN E001 E000 E20X
> ---- ---- ---- ------
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论