Skip to content

Commit f8ee751

Browse files
Update round to add mode (#2560)
* Update 1.math.md * update * update * update
1 parent e153f27 commit f8ee751

File tree

2 files changed

+104
-4
lines changed
  • docs-2.0-en/3.ngql-guide/6.functions-and-expressions
  • docs-2.0-zh/3.ngql-guide/6.functions-and-expressions

2 files changed

+104
-4
lines changed

docs-2.0-en/3.ngql-guide/6.functions-and-expressions/1.math.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,19 @@ nebula> RETURN ceil(9.1);
7575

7676
round() returns the rounded value of the specified number. Pay attention to the floating-point precision when using this function.
7777

78-
Syntax: `round(<expression>, <digit>)`
78+
Syntax: `round(<expression>, <precision>, <mode>)`
7979

8080
- `expression`: An expression of which the result type is double.
8181

82-
- `digit`: Decimal digits. If `digit` is less than 0, round at the left of the decimal point.
82+
- `precision`: An integer specifying the precision. If `precision` is less than 0, round at the left of the decimal point.
8383

84+
- `mode`: A string specifying the rounding mode. Optional. The following valid values are supported:
85+
- `DOWN`: Round towards zero.
86+
- `CEILING`: Round towards positive infinity.
87+
- `FLOOR`: Round towards negative infinity.
88+
- `HALF_UP`: Round towards the closest value of the given precision, with ties being rounded away from zero.
89+
- `HALF_DOWN`: Round towards the closest value of the given precision, with ties being rounded towards zero.
90+
- `HALF_EVEN`: Round towards the closest value of the given precision, with ties being rounded to the nearest even number.
8491
- Result type: Double
8592

8693
Example:
@@ -92,12 +99,56 @@ nebula> RETURN round(314.15926, 2);
9299
+--------------------+
93100
| 314.16 |
94101
+--------------------+
102+
95103
nebula> RETURN round(314.15926, -1);
96104
+-----------------------+
97105
| round(314.15926,-(1)) |
98106
+-----------------------+
99107
| 310.0 |
100108
+-----------------------+
109+
110+
nebula> RETURN round(314.15926, 2, "DOWN");
111+
+---------------------------+
112+
| round(314.15926,2,"DOWN") |
113+
+---------------------------+
114+
| 314.15 |
115+
+---------------------------+
116+
117+
nebula> RETURN round(314.15926, 2, "CEILING");
118+
+------------------------------+
119+
| round(314.15926,2,"CEILING") |
120+
+------------------------------+
121+
| 314.16 |
122+
+------------------------------+
123+
124+
nebula> RETURN round(314.15926, 2, "FLOOR");
125+
+----------------------------+
126+
| round(314.15926,2,"FLOOR") |
127+
+----------------------------+
128+
| 314.15 |
129+
+----------------------------+
130+
131+
nebula> RETURN round(314.15, 1, "HALF_UP");
132+
+---------------------------+
133+
| round(314.15,1,"HALF_UP") |
134+
+---------------------------+
135+
| 314.2 |
136+
+---------------------------+
137+
138+
nebula> RETURN round(314.15, 1, "HALF_DOWN");
139+
+-----------------------------+
140+
| round(314.15,1,"HALF_DOWN") |
141+
+-----------------------------+
142+
| 314.1 |
143+
+-----------------------------+
144+
145+
nebula> RETURN round(314.15, 1, "HALF_EVEN");
146+
+-----------------------------+
147+
| round(314.15,1,"HALF_EVEN") |
148+
+-----------------------------+
149+
| 314.2 |
150+
+-----------------------------+
151+
101152
```
102153

103154
## sqrt()

docs-2.0-zh/3.ngql-guide/6.functions-and-expressions/1.math.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,19 @@ nebula> RETURN ceil(9.1);
7676

7777
round() 返回指定数字四舍五入后的值。极端情况下请注意浮点数的精度问题。
7878

79-
语法:`round(<expression>, <digit>)`
79+
语法:`round(<expression>, <precision>, <mode>)`
8080

8181
- `expression`:结果的数据类型为 double 的表达式。
8282

83-
- `digit`:小数位数。小于 0 时 ,在小数点左侧做四舍五入。数据类型为 int
83+
- `precision`:代表精度的整数。小于 0 时 ,在小数点左侧做四舍五入。
8484

85+
- `mode`:代表舍入模式的字符串。可选参数。可选值如下:
86+
- `DOWN`:向零舍入。
87+
- `CEILING`:向正无穷舍入。
88+
- `FLOOR`:向负无穷舍入。
89+
- `HALF_UP`:基于精度向最接近的值舍入,如果最接近的值有两个,则取远离零的值。
90+
- `HALF_DOWN`:基于精度向最接近的值舍入,如果最接近的值有两个,则取靠近零的值。
91+
- `HALF_EVEN`:基于精度向最接近的值舍入,如果最接近的值有两个,则取最接近的偶数值。
8592
- 返回类型:double。
8693

8794
示例:
@@ -100,6 +107,48 @@ nebula> RETURN round(314.15926, -1);
100107
+-----------------------+
101108
| 310.0 |
102109
+-----------------------+
110+
111+
nebula> RETURN round(314.15926, 2, "DOWN");
112+
+---------------------------+
113+
| round(314.15926,2,"DOWN") |
114+
+---------------------------+
115+
| 314.15 |
116+
+---------------------------+
117+
118+
nebula> RETURN round(314.15926, 2, "CEILING");
119+
+------------------------------+
120+
| round(314.15926,2,"CEILING") |
121+
+------------------------------+
122+
| 314.16 |
123+
+------------------------------+
124+
125+
nebula> RETURN round(314.15926, 2, "FLOOR");
126+
+----------------------------+
127+
| round(314.15926,2,"FLOOR") |
128+
+----------------------------+
129+
| 314.15 |
130+
+----------------------------+
131+
132+
nebula> RETURN round(314.15, 1, "HALF_UP");
133+
+---------------------------+
134+
| round(314.15,1,"HALF_UP") |
135+
+---------------------------+
136+
| 314.2 |
137+
+---------------------------+
138+
139+
nebula> RETURN round(314.15, 1, "HALF_DOWN");
140+
+-----------------------------+
141+
| round(314.15,1,"HALF_DOWN") |
142+
+-----------------------------+
143+
| 314.1 |
144+
+-----------------------------+
145+
146+
nebula> RETURN round(314.15, 1, "HALF_EVEN");
147+
+-----------------------------+
148+
| round(314.15,1,"HALF_EVEN") |
149+
+-----------------------------+
150+
| 314.2 |
151+
+-----------------------------+
103152
```
104153

105154
## sqrt()

0 commit comments

Comments
 (0)