Support Questions

Find answers, ask questions, and share your expertise

Hive float datatype issue !!!

avatar
Explorer

Hello, i'm currently using CDH 5.2

 

I've a sample data like this :

0
18.6
36.1
53.7
86.5

but when i'm upload to hive with float type, i got this :

0.0

18.6000003815

36.0999984741

53.7000007629

86.5

I don't understand why 18.6 become 18.6000003815 , but 86.5 is still the same, every other variable is change except the .0 and .5 varible.

 

Can someone explain to me, really appreciate the help, thanks !

1 ACCEPTED SOLUTION

avatar
Rising Star

This behavior is like any system with float representation, float bit representation does not allow exact representation of most values.  There is a lot of literature on the subject like  http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

 

If you want exact values it's better to go with decimal, where you can specify scale and precision.

 

Thanks

Szehon

View solution in original post

1 REPLY 1

avatar
Rising Star

This behavior is like any system with float representation, float bit representation does not allow exact representation of most values.  There is a lot of literature on the subject like  http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

 

If you want exact values it's better to go with decimal, where you can specify scale and precision.

 

Thanks

Szehon