Dileep Dominic
Dileep Dominic

Reputation: 519

How to show decimal point in hive?

I want to display the decimal precision along with the result for decimal datatype in hive. However if there is no fraction part , in hive it will not display the decimal points.

hive> select cast(11 as decimal(14,2));
11

hive> select cast(11.22 as decimal(14,2));
11.22

In the above example instead of 11 it should display 11.00.How to achieve this? Please help.

Upvotes: 0

Views: 4705

Answers (2)

nobody
nobody

Reputation: 11080

The following format_number() function should do it.Source, return type will be string though.

select format_number(11,2)

Note: Precision and Scale were added from Hive 0.13.

Upvotes: 1

user10434643
user10434643

Reputation:

Use round or float_number to set the decimal point where u like , example :

select round(SUM(150.100 + 127.0090), 2);

  • or

select float_number(var,2);

Upvotes: -1

Related Questions