BigQuery中的NUMERIC和FLOAT有什么区别? [英] What is the difference between NUMERIC and FLOAT in BigQuery?
问题描述
我阅读了以下文档: https://cloud.google.com/bigquery/docs/reference /standard-sql/data-types https://cloud.google.com/bigquery/pricing#data
I read the docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types https://cloud.google.com/bigquery/pricing#data
我知道FLOAT
是8个字节,而NUMERIC
是16个字节
那是唯一的区别吗?
文档说NUMERIC
的范围可以从-99999999999999999999999999999.999999999
到99999999999999999999999999999.999999999
,但是没有指定FLOAT
的范围.
I know that FLOAT
is 8 bytes while NUMERIC
is 16 bytes
Is that the only difference?
The docs says that NUMERIC
can range -99999999999999999999999999999.999999999
to 99999999999999999999999999999.999999999
but it doesn't specify the range for FLOAT
.
推荐答案
我喜欢当前的答案.我想添加这个作为为什么需要NUMERIC
的证明:
I like the current answers. I want to add this as a proof of why NUMERIC
is necessary:
SELECT
4.35 * 100 a_float
, CAST(4.35 AS NUMERIC) * 100 a_numeric
这不是错误-这正是 IEEE定义浮点数的处理方式.同时NUMERIC
表现出的行为更接近人类的期望.
This is not a bug - this is exactly how the IEEE defines floats should be handled. Meanwhile NUMERIC
exhibits behavior closer to what humans expect.
为进一步证明NUMERIC
有用性,此答案显示NUMERIC
如何处理对于JavaScript无法正常处理的数字太大.
For another proof of NUMERIC
usefulness, this answer shows how NUMERIC
can handle numbers too big for JavaScript to normally handle.
在将此问题归咎于BigQuery之前,您可以检查大多数其他编程语言是否会执行相同的操作. Python,例如:
Before you blame BigQuery for this problem, you can check that most other programming languages will do the same. Python, for example:
这篇关于BigQuery中的NUMERIC和FLOAT有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!