英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论