Reputation: 355
I am trying to add two numbers using Hive SQL.
select 4.6 + 3.1 from <table> => 7.699999999999999
But,
select 4.7 +3.2 from <table> => 7.9
I understand that rounding of result will give the expected output but the question is why this different behavior in first place?
I am using hive 2.11 (hive context) with Apache spark 1.6.2.
Upvotes: 1
Views: 1492
Reputation: 1606
What you have observed is not Hive specific. Example:
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
>>> 4.7+3.2
7.9
>>> 4.6+3.1
7.699999999999999
It's related to how the double numbers are stored in memory in some languages (floating-point): https://en.wikipedia.org/wiki/Floating_point#Internal_representation
See also:
Upvotes: 1