gpt4 book ai didi

hadoop - 配置单元中的小数精度

转载 作者:可可西里 更新时间:2023-11-01 15:02:11 26 4
gpt4 key购买 nike

我想添加要为值设置的小数精度

示例:

select 1*1.00000;

输出:1.0

甚至尝试过 cast

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

输出:1

我希望结果显示为 1.000。有没有办法在 hive 中这样做?

最佳答案

创建一个表并测试它。如果我们给出 decimal 函数中提到的精确精度值,它就会起作用。

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

因此,如果该值与 decimal 函数匹配,则它会正确显示,否则它会缩小或转换为 NULL。

关于hadoop - 配置单元中的小数精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36281298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com