小编Ana*_*abu的帖子

为什么在float中存储的相同值与Java中的double之间存在差异?

我期望以下代码生成:" Both are equal",但我得到了" Both are NOT equal":

float a=1.3f;
double b=1.3;
if(a==b)
{
 System.out.println("Both are equal");
}
else{
 System.out.println("Both are NOT equal");
}
Run Code Online (Sandbox Code Playgroud)

这是什么原因?

java math floating-point precision

5
推荐指数
2
解决办法
1182
查看次数

标签 统计

floating-point ×1

java ×1

math ×1

precision ×1