Wesley Kluckhohn
Wesley Kluckhohn

Reputation: 115

Hive cast string to floating decimal

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

Upvotes: 6

Views: 45382

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271231

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.

Upvotes: 13

Related Questions