Harry Harish
Harry Harish

Reputation: 13

Decimal precision in hive

I want to add the decimal precision to be set for the values

Example:

select 1*1.00000;

output: 1.0

Even tried with cast

select cast(cast(1*1.0000 as double) as decimal(5,2))

output: 1

I want the results to be displayed as 1.000. Is there any way to do so in hive?

Upvotes: 1

Views: 17992

Answers (1)

Vignesh I
Vignesh I

Reputation: 2221

Create a table and test it. It works if we give the exact precision value as mentioned in the decimal function.

create table test1_decimal (b decimal (5,3));

INSERT INTO test1_Decimal values(1.000); //This will shrink it to 1 as the total digits is not five.

INSERT INTO test1_Decimal values(123.12345); //This results in NULL as it exceeds the total digits(5).

INSERT INTO test1_Decimal values(12.123); //This will give you exact result as the precision and number of digits fits. Ouputs as 12.123

So if the value matches the decimal function then it displays correctly else it shrinks or converts to NULL.

Upvotes: 7

Related Questions