17

Actually I'm looking for more details about the sum function in Apache Hive. Until now, I understood that I can specify the number of digits after the dot:

val DECIMAL(18, 3)

But what I can not find is the precision scale in case of sum. If I add 2 decimals with a precision scale of 3 for example, what will be the return of the sum function? My precision scale will be preserved? The result will be truncated or rounded? What have I missed?

Thanks a lot.

DK5
  • 317
  • 3
  • 15
Régis NIOX
  • 741
  • 2
  • 12
  • 30

1 Answers1

33

Just round it to as many decimal places as you want.

select round(SUM(150.100 + 127.0090), 2);

Output of above will be:-

277.11
Jack Daniel's
  • 2,583
  • 22
  • 28
  • 5
    I'm using Hive (version 1.1.0-cdh5.10.1). Trying your query through HUE, it returns 277.11000000000001. Then I tried it through beeline and I got the correct result (277.11). Even writing the result to a file works fine. I think it's a bug with HUE UI! – pedram bashiri Nov 08 '17 at 16:49