ClickHouse/docs/zh/data_types/float.md
ogorbacheva abae86f7a6 Doc fixes: remove double placeholders; add them where missing. (#3923)
* Doc fix: add spaces where missing

* Doc fixes: rm double spaces

* Doc fixes: edit spaces

* Doc fixes: rm double spaces in /fa

* Revert "Doc fixes: rm double spaces in /fa"

This reverts commit bb879a62ef.

* Doc fix: resolve all problems with double spaces in /fa

* Doc fix: add spaces for readability

* Doc fix: add spaces

* Fix spaces
2018-12-25 18:25:43 +03:00

73 lines
1.6 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.

# Float32, Float64
[浮点数](https://en.wikipedia.org/wiki/IEEE_754)。
类型与以下 C 语言中类型是相同的:
- `Float32` - `float`
- `Float64` - `double`
我们建议您尽可能以整数形式存储数据。例如,将固定精度的数字转换为整数值,例如货币数量或页面加载时间用毫秒为单位表示
## 使用浮点数
- 对浮点数进行计算可能引起四舍五入的误差。
```sql
SELECT 1 - 0.9
```
```
┌───────minus(1, 0.9)─┐
│ 0.09999999999999998 │
└─────────────────────┘
```
- 计算的结果取决于计算方法(计算机系统的处理器类型和体系结构)
- 浮点计算结果可能是诸如无穷大(`INF`)和"非数字"`NaN`)。对浮点数计算的时候应该考虑到这点。
- 当一行行阅读浮点数的时候,浮点数的结果可能不是机器最近显示的数值。
## NaN and Inf
与标准SQL相比ClickHouse 支持以下类别的浮点数:
- `Inf` 正无穷
```sql
SELECT 0.5 / 0
```
```
┌─divide(0.5, 0)─┐
│ inf │
└────────────────┘
```
- `-Inf` 负无穷
```sql
SELECT -0.5 / 0
```
```
┌─divide(-0.5, 0)─┐
│ -inf │
└─────────────────┘
```
- `NaN` 非数字
```
SELECT 0 / 0
```
```
┌─divide(0, 0)─┐
│ nan │
└──────────────┘
```
可以在 [ORDER BY 子句](../query_language/select.md) 查看更多关于 ` NaN` 排序的规则。