gpt4 book ai didi

java - 大值的 double 到 long 转换不会产生相同的值

转载 作者:行者123 更新时间:2023-11-30 02:25:04 26 4
gpt4 key购买 nike

double d = 1000000000138719341D;
System.out.print(Double.valueOf(d).longValue());

打印结果为

1000000000138719360

为什么不一样?我怎样才能得到正确的结果?

最佳答案

来自docs :

double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

关于java - 大值的 double 到 long 转换不会产生相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45852226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com