问题描述
我想在Hive中将具有科学计数法的数字转换为Decimal,但是输出错误.我在哪里做错了..
I want to cast the number which has scientific notation to Decimal in Hive, But I am getting wrong output. Where I am doing wrong..
下面是我要测试的查询.
Below is my query to test.
select cast(-1.36666E2 as decimal(6,1))
我希望输出为 -1.36666 .但是我得到了 -136.7
I am expecting the output to be -1.36666 . But I got -136.7
推荐答案
DECIMAL(精度,小数位数)是数据类型.
DECIMAL(precision, scale) is the data type.
精度是数字中的位数.小数位数是数字中小数点右边的位数.
Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number.
例如,数字136.7的精度为4,小数位数为1因此,如果您拥有1.36666,则精度为6,小数位数为5
For example, the number 136.7 has a precision of 4 and a scale of 1So if you have 1.36666 , precision is 6 and a scale of 5
select cast(-1.36666E2 as decimal(6,3))
-1.36666E2为-1.36666 * 10 ^ 2.那将返回-136.666.输入-1.36666E2不会得到-1.36666
-1.36666E2 is -1.36666* 10^2. That will return -136.666. You will not get -1.36666 for the input -1.36666E2
这篇关于将Hive中的科学数字转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!