2016-09-01 40 views
1

我想使用Hive SQL添加两个数字。添加两个十进制数Hive SQL

select 4.6 + 3.1 from <table> => 7.699999999999999 

但是,

select 4.7 +3.2 from <table> => 7.9 

我明白四舍五入的结果将得到所需要的输出,但问题是,为什么在首位此不同的行为?

我在Apache Spark 1.6.2中使用hive 2.11(hive上下文)。

回答

1

您观察到的不是Hive特定的。例如:

Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
>>> 4.7+3.2 
7.9 
>>> 4.6+3.1 
7.699999999999999 

它涉及到双数字是如何存储在内存中的一些语言(浮点): https://en.wikipedia.org/wiki/Floating_point#Internal_representation

参见:

+0

对不起d elay!谢谢回答。公认。 – Aiden