Why does 0.06 + 0.01 = 0.07 in ColdFusion?(为什么在 ColdFusion 中 0.06 + 0.01 = 0.07?)
问题描述
为什么 ColdFusion 中的数学运算似乎不受浮点数学问题的影响?拿下代码:
Why don't math operations in ColdFusion seem to be affected by floating point math issues? Take the code:
result = 0.06 + 0.01;
writedump(result);
writedump(result.getClass().getName());
哪些输出
0.07
java.lang.Double
java.lang.Double
然而,当添加两个双精度时,等效的 Java 代码会产生我所期望的结果:
However the equivlant Java code produces what I"d expect when adding two doubles:
public static void main(String[] args) {
double a = 0.01d;
double b = 0.06d;
System.out.println(a + b); //0.06999999999999999
}
这是我期望从 ColdFusion 看到的,因为浮动数学的现实(http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html).
This is what I'd expect to see from ColdFusion because of the realities of floating math (http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html).
ColdFusion 是在幕后做了一些魔术"还是我在这里看到了一个孤立的异常?
Does ColdFusion do some "magic" behind the scenes or am I looking at an isolated anomaly here?
推荐答案
我强烈怀疑它只是在 输出 上舍入不同.换句话说,问题仍然存在 - 当使用 writedump 打印出这个特定值时,它恰好没有出现.
I strongly suspect it's simply rounding differently on output. In other words, the issue is still there - it just happens not to show up when this particular value is printed out with writedump.
如果你使用会发生什么:
What happens if you use:
writedump(String.valueOf(result));
?
这篇关于为什么在 ColdFusion 中 0.06 + 0.01 = 0.07?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么在 ColdFusion 中 0.06 + 0.01 = 0.07?
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
