How to display input integer in decimal format based on input precision and scale


#1

Hi Everyone,
How can I display decimal value based on precision and scale in hive? for example,
I have a input value 1234 and want to display it as 12.34 if my input precision and scale is (4,2) I tried this using cast but it didn’t work ,it is giving null , see below.

hive (default)> select cast(‘1234’ as decimal(4,2));
OK
NULL
Time taken: 2.673 seconds, Fetched: 1 row(s)
hive (default)>

Thanks
Puru


#2

Try this.
select cast(‘1234’ as decimal(6,2));
Here 6 is the total length of the number including the digits after the decimal point and 2 is the number of digits after the decimal point.