diff --git a/src/core/etl/src/Flow/ETL/Function/Round.php b/src/core/etl/src/Flow/ETL/Function/Round.php index ef49e271e..5ae982038 100644 --- a/src/core/etl/src/Flow/ETL/Function/Round.php +++ b/src/core/etl/src/Flow/ETL/Function/Round.php @@ -15,7 +15,7 @@ public function __construct( ) { } - public function eval(Row $row) : ?float + public function eval(Row $row) : int|float|null { $value = (new Parameter($this->value))->asNumber($row); $precision = (new Parameter($this->precision))->asInt($row); @@ -29,6 +29,6 @@ public function eval(Row $row) : ?float $mode = 1; } - return \round($value, $precision, $mode); + return $precision === 0 ? (int) \round($value, $precision, $mode) : \round($value, $precision, $mode); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php index 19dbe14a4..1e42bd585 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php @@ -464,9 +464,9 @@ public function test_window_avg_function() : void self::assertSame( [ - ['department' => 'Sales', 'avg_salary' => 3917.0], - ['department' => 'Marketing', 'avg_salary' => 2940.0], - ['department' => 'Finance', 'avg_salary' => 3550.0], + ['department' => 'Sales', 'avg_salary' => 3917], + ['department' => 'Marketing', 'avg_salary' => 2940], + ['department' => 'Finance', 'avg_salary' => 3550], ], df() ->from(from_all(from_memory($memoryPage1), from_memory($memoryPage2))) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RoundTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RoundTest.php new file mode 100644 index 000000000..02dbf8ff1 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RoundTest.php @@ -0,0 +1,36 @@ +round(lit(2))->eval(row(float_entry('float', 10.123))) + ); + + self::assertIsFloat( + ref('float')->round(lit(2))->eval(row(float_entry('float', 10.123))) + ); + } + + public function test_round_with_precision_0() : void + { + self::assertEquals( + 10, + ref('float')->round(lit(0))->eval(row(float_entry('float', 10.123))) + ); + + self::assertIsInt( + ref('float')->round(lit(0))->eval(row(float_entry('float', 10.123))) + ); + } +}