java中双精度乘法的精度? [英] Accuracy of double precision multiplication in java?

查看:226
本文介绍了java中双精度乘法的精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java中double值的乘法运算符的保证精度是多少?

例如,2.2 * 100是220.00000000000003,但是220是一个双数。 220.00000000000003是220后的下一个double。

解决方案

乘法工作正常,但 2.2 不能完全表示为双精度。最接近的双打是:


  • 2.199999999999999733(0x4001999999999999)
  • 2.200000000000000177(0x400199999999999a)



  • 有些软件会把后面的值打印成 2.2 ,但这并不意味着它是准确的。这只是意味着它被视为足够接近。


    What is the guaranteed accuracy of multiplication operator for double values in java?

    For example, 2.2 * 100 is 220.00000000000003, but 220 is a double number. 220.00000000000003 is the next double after 220.

    解决方案

    The multiplication is working fine, but 2.2 cannot be represented exactly as a double. The closest doubles are:

    • 2.199999999999999733 (0x4001999999999999)
    • 2.200000000000000177 (0x400199999999999a)

    Some software will print the latter value as 2.2, but that doesn't mean it's exact. It just means it's treated as "close enough".

    这篇关于java中双精度乘法的精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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