Athena gets order of operations wrong

huangapple go评论63阅读模式
英文:

Athena gets order of operations wrong

问题

Athena在这里做什么?

select
(10.0*12+10/10000)

它返回一个值为120.0。

我知道它没有四舍五入,因为代码中的"10"和"12"都是小于0.01的小数。

英文:

What is Athena doing here?

select
(10.0*12+10/10000)

It returns a value of 120.0

I know it's not rounding off because the "10" and the "12" in my code are small fractions < 0.01.

答案1

得分: 1

你被另一个整数除法案例所困扰。10/10000 在求和和类型之前被计算,因此 10/10000 结果的类型由参与除法的类型确定,因此 select typeof(10/10000)integer,将操作数之一更改为 double(可能具有正确的精度):

select (10.0*12 + 10.000/10000);

输出:

  _col0  
---------
 120.001 
英文:

You got struck by another case of integer division. 10/10000 is calculated before the sum and type of 10/10000 result is determined by the types taking part in the division, hence select typeof(10/10000) is integer, change one of operands to be double (potentially with correct precision):

select (10.0*12 + 10.000/10000);

Output:

  _col0  
---------
 120.001 

huangapple
  • 本文由 发表于 2023年5月24日 19:51:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定