From 7183b7cce2dd8178a9ae8a37569f5d95395c73f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louise=20S=C3=B6derstr=C3=B6m?= Date: Thu, 8 Dec 2022 15:12:09 +0100 Subject: [PATCH] Update docs about round() function. (#230) We follow the behaviour of Java, i.e. rounding towards positive infinity for ties when we have no precision or mode or rounding according to https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/math/RoundingMode.html for rounding modes. The current description was wrong in some cases and missleading in others. Also added more examples. Fixes #https://github.com/neo4j/neo4j/issues/12972 and https://github.com/neo4j/neo4j/issues/12963 --- .../pages/functions/mathematical-numeric.adoc | 274 ++++++++++++++++-- 1 file changed, 251 insertions(+), 23 deletions(-) diff --git a/modules/ROOT/pages/functions/mathematical-numeric.adoc b/modules/ROOT/pages/functions/mathematical-numeric.adoc index adfee7017..728126905 100644 --- a/modules/ROOT/pages/functions/mathematical-numeric.adoc +++ b/modules/ROOT/pages/functions/mathematical-numeric.adoc @@ -342,7 +342,7 @@ A random number is returned. [[functions-round]] == round() -`round()` returns the value of the given number rounded to the nearest integer, with half-way values always rounded up. +`round()` returns the value of the given number rounded to the nearest integer, with ties always rounded towards positive infinity. *Syntax:* @@ -400,11 +400,31 @@ RETURN round(3.141592) ====== +.+round() of negative number with tie+ +====== + +.Query +[source, cypher, indent=0] +---- +RETURN round(-1.5) +---- + +Ties are rounded towards positive infinity, therfore `-1.0` is returned. + +.Result +[role="queryresult",options="header,footer",cols="1*> without precision. *Syntax:* @@ -438,12 +458,12 @@ round(expression, precision) |=== -| `round(null)` returns `null`. +| `round()` returns `null` if any of its input parameters are `null`. |=== -.+round()+ +.+round() with precision+ ====== .Query @@ -466,6 +486,52 @@ RETURN round(3.141592, 3) ====== +.+round() with precision 0 and tie+ +====== + +.Query +[source, cypher, indent=0] +---- +RETURN round(-1.5, 0) +---- + +To align with `round(-1.5)`, `-1.0` is returned. + +.Result +[role="queryresult",options="header,footer",cols="1*