From 10723160b392c5c9b54718ed7c4f354dd4ffda16 Mon Sep 17 00:00:00 2001 From: Denny Crane Date: Tue, 14 Sep 2021 00:13:54 -0300 Subject: [PATCH 1/2] Update rounding-functions.md --- .../functions/rounding-functions.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/ru/sql-reference/functions/rounding-functions.md b/docs/ru/sql-reference/functions/rounding-functions.md index 276f85bf6b7..1eede1ea57c 100644 --- a/docs/ru/sql-reference/functions/rounding-functions.md +++ b/docs/ru/sql-reference/functions/rounding-functions.md @@ -27,7 +27,7 @@ N может быть отрицательным. Округляет значение до указанного десятичного разряда. -Функция возвращает ближайшее значение указанного порядка. В случае, когда заданное число равноудалено от чисел необходимого порядка, функция возвращает то из них, которое имеет ближайшую чётную цифру (банковское округление). +Функция возвращает ближайшее значение указанного порядка. В случае, когда заданное число равноудалено от чисел необходимого порядка, для типов с плавающей точкой (Float32/64) функция возвращает то из них, которое имеет ближайшую чётную цифру (банковское округление), для типов с фиксированной точкой (Decimal) функция использует округление в бо́льшую по модулю сторону (математическое округление). ``` sql round(expression [, decimal_places]) @@ -47,7 +47,7 @@ round(expression [, decimal_places]) ### Примеры {#primery} -**Пример использования** +**Пример использования с Float** ``` sql SELECT number / 2 AS x, round(x) FROM system.numbers LIMIT 3 @@ -61,6 +61,21 @@ SELECT number / 2 AS x, round(x) FROM system.numbers LIMIT 3 └─────┴──────────────────────────┘ ``` +**Пример использования с Decimal** + + +``` sql +SELECT cast(number / 2 AS Decimal(10,4)) AS x, round(x) FROM system.numbers LIMIT 3 +``` + +``` text +┌──────x─┬─round(CAST(divide(number, 2), 'Decimal(10, 4)'))─┐ +│ 0.0000 │ 0.0000 │ +│ 0.5000 │ 1.0000 │ +│ 1.0000 │ 1.0000 │ +└────────┴──────────────────────────────────────────────────┘ +``` + **Примеры округления** Округление до ближайшего числа. From efd4ac381b010f42d0e0194d82c7f788aef7c04a Mon Sep 17 00:00:00 2001 From: Denny Crane Date: Tue, 14 Sep 2021 00:19:17 -0300 Subject: [PATCH 2/2] Update rounding-functions.md --- .../functions/rounding-functions.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/en/sql-reference/functions/rounding-functions.md b/docs/en/sql-reference/functions/rounding-functions.md index 5f74c6329d1..f564f15659c 100644 --- a/docs/en/sql-reference/functions/rounding-functions.md +++ b/docs/en/sql-reference/functions/rounding-functions.md @@ -29,7 +29,7 @@ Returns the round number with largest absolute value that has an absolute value Rounds a value to a specified number of decimal places. -The function returns the nearest number of the specified order. In case when given number has equal distance to surrounding numbers, the function uses banker’s rounding for float number types and rounds away from zero for the other number types. +The function returns the nearest number of the specified order. In case when given number has equal distance to surrounding numbers, the function uses banker’s rounding for float number types and rounds away from zero for the other number types (Decimal). ``` sql round(expression [, decimal_places]) @@ -49,7 +49,7 @@ The rounded number of the same type as the input number. ### Examples {#examples} -**Example of use** +**Example of use with Float** ``` sql SELECT number / 2 AS x, round(x) FROM system.numbers LIMIT 3 @@ -63,6 +63,20 @@ SELECT number / 2 AS x, round(x) FROM system.numbers LIMIT 3 └─────┴──────────────────────────┘ ``` +**Example of use with Decimal** + +``` sql +SELECT cast(number / 2 AS Decimal(10,4)) AS x, round(x) FROM system.numbers LIMIT 3 +``` + +``` text +┌──────x─┬─round(CAST(divide(number, 2), 'Decimal(10, 4)'))─┐ +│ 0.0000 │ 0.0000 │ +│ 0.5000 │ 1.0000 │ +│ 1.0000 │ 1.0000 │ +└────────┴──────────────────────────────────────────────────┘ +``` + **Examples of rounding** Rounding to the nearest number.