From 4718fb9bfb9f7fe7cd4c614942b18d539a470615 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 d3457f98c..441130d14 100644 --- a/modules/ROOT/pages/functions/mathematical-numeric.adoc +++ b/modules/ROOT/pages/functions/mathematical-numeric.adoc @@ -277,7 +277,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:* @@ -335,11 +335,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:* @@ -373,12 +393,12 @@ round(expression, precision) |=== -| `round(null)` returns `null`. +| `round()` returns `null` if any of its input parameters are `null`. |=== -.+round()+ +.+round() with precision+ ====== .Query @@ -401,6 +421,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*