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


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));
Time taken: 2.673 seconds, Fetched: 1 row(s)
hive (default)>



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.


Thanks Bennet for your reply and sorry for coming late on this. the cast didn’t work for us so we created a udf to handle such scenario.