ClickHouse/docs/zh/query_language/functions/rounding_functions.md
Ivan Blinkov 2e1f6bc56d
[experimental] add "es" docs language as machine translated draft (#9787)
* replace exit with assert in test_single_page

* improve save_raw_single_page docs option

* More grammar fixes

* "Built from" link in new tab

* fix mistype

* Example of include in docs

* add anchor to meeting form

* Draft of translation helper

* WIP on translation helper

* Replace some fa docs content with machine translation

* add normalize-en-markdown.sh

* normalize some en markdown

* normalize some en markdown

* admonition support

* normalize

* normalize

* normalize

* support wide tables

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* normalize

* lightly edited machine translation of introdpection.md

* lightly edited machhine translation of lazy.md

* WIP on translation utils

* Normalize ru docs

* Normalize other languages

* some fixes

* WIP on normalize/translate tools

* add requirements.txt

* [experimental] add es docs language as machine translated draft

* remove duplicate script

* Back to wider tab-stop (narrow renders not so well)
2020-03-21 07:11:51 +03:00

87 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 取整函数 {#qu-zheng-han-shu}
## floor(x\[, N\]) {#floorx-n}
返回小于或等于x的最大舍入数。该函数使用参数乘1/10N如果1/10N不精确则选择最接近的精确的适当数据类型的数。
N是一个整数常量可选参数。默认为0这意味着不对其进行舍入。
N可以是负数。
示例: `floor(123.45, 1) = 123.4, floor(123.45, -1) = 120.`
`x`是任何数字类型。结果与其为相同类型。
对于整数参数使用负N值进行舍入是有意义的对于非负«N»该函数不执行任何操作
如果取整导致溢出例如floor(-128-1)),则返回特定于实现的结果。
## ceil(x\[, N\]), ceiling(x\[, N\]) {#ceilx-n-ceilingx-n}
返回大于或等于x的最小舍入数。在其他方面它与floor功能相同见上文
## round(x\[, N\]) {#rounding-functions-round}
将值取整到指定的小数位数。
该函数按顺序返回最近的数字。如果给定数字包含多个最近数字,则函数返回其中最接近偶数的数字(银行的取整方式)。
round(expression [, decimal_places])
**参数:**
- `expression` — 要进行取整的数字。可以是任何返回数字[类型](../../data_types/index.md#data_types)的[表达式](../syntax.md#syntax-expressions)。
- `decimal-places` — 整数类型。
- 如果`decimal-places > 0`,则该函数将值舍入小数点右侧。
- 如果`decimal-places < 0`则该函数将小数点左侧的值四舍五入
- 如果`decimal-places = 0`,则该函数将该值舍入为整数。在这种情况下,可以省略参数。
**返回值:**
与输入数字相同类型的取整后的数字
### 示例 {#shi-li}
**使用示例**
``` sql
SELECT number / 2 AS x, round(x) FROM system.numbers LIMIT 3
```
┌───x─┬─round(divide(number, 2))─┐
0 0
0.5 0
1 1
└─────┴──────────────────────────┘
**取整的示例**
取整到最近的数字
round(3.2, 0) = 3
round(4.1267, 2) = 4.13
round(22,-1) = 20
round(467,-2) = 500
round(-467,-2) = -500
银行的取整
round(3.5) = 4
round(4.5) = 4
round(3.55, 1) = 3.6
round(3.65, 1) = 3.6
## roundToExp2(num) {#roundtoexp2num}
接受一个数字如果数字小于1则返回0否则它将数字向下舍入到最接近的整个非负2的x次幂
## roundDuration(num) {#rounddurationnum}
接受一个数字如果数字小于1则返回0否则它将数字向下舍入为集合中的数字110306012018024030060012001800360072001800036000此函数用于Yandex.Metrica报表中计算会话的持续时长
## roundAge(num) {#roundagenum}
接受一个数字如果数字小于18则返回0否则它将数字向下舍入为集合中的数字1825354555此函数用于Yandex.Metrica报表中用户年龄的计算
## roundDown(num, arr) {#rounddownnum-arr}
接受一个数字将其向下舍入到指定数组中的元素如果该值小于数组中的最低边界则返回最低边界
[来源文章](https://clickhouse.tech/docs/en/query_language/functions/rounding_functions/) <!--hide-->