Hive 从 Double 转换为 String 不在科学中 [英] Hive Converting from Double to String Not in Scientific

查看:20
本文介绍了Hive 从 Double 转换为 String 不在科学中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列双精度类型的表,我正在尝试将其从双精度转换为字符串.

I have a table with a column double type, and I am trying to convert that from double to string.

但是,当我使用 cast 命令时,它巧妙地"将其转换为科学记数法.如下图:

However, when I use the cast command, it "smartly" convert that into scientific notation. like below:

select 
    number, 
    cast(number as string), 
from ...

看起来像

number     c1_
9999999902  9.999999902E9
9999999902  9.999999902E9
9999999902  9.999999902E9
9999999902  9.999999902E9
9999999909  9.999999909E9

谁能告诉我如何避免将其转换为科学并保留原始文本?

Can anyone show me how to avoid converting that into scientific and keep the raw text?

推荐答案

Hive 将 double 转换为科学表示,同时将其转换为字符串,因为 Hive 以相同的方式对待 double 本身.因此,问题不在于强制转换为字符串.

Hive converts double to scientific representation while cast to string because Hive treats double itself in a same way. Therefore, problem is not with cast to string.

见下例:

 select 9999999902.0, cast(9999999902.0 as BIGINT), cast(cast(9999999902.0 as BIGINT)  as string) from ..

输出:

OK
9.999999902E9   9999999902

这篇关于Hive 从 Double 转换为 String 不在科学中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆