Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive cast string to floating decimal

Tags:

sql

casting

hive

I am trying to cast a string field with a variable decimal to double. The problem I'm running into is that because the decimal is variable and can be any one of the following:

359.879999
35.8799999
3.59879999

(move the decimal wherever you want to...but the length of the field is always 9)

I have tried to do:

cast(RECURR as float) as RECURR

but that is just returning:

359.880004882813

I have tried:

cast(RECURR as decimal) as RECURR

and that returns:

360
like image 707
Wesley Kluckhohn Avatar asked Dec 23 '22 08:12

Wesley Kluckhohn


1 Answers

How about trying:

select cast(recurr as decimal(19, 9))

This should be appropriate for anywhere where the decimal place lurks.

Do note that the unused decimal places will be zeroes.

like image 97
Gordon Linoff Avatar answered Jan 02 '23 19:01

Gordon Linoff