此代码不起作用。有什么建议吗?
float tempNum = 0.590000;
int temporary;
if (tempNum >= 0.590000 && tempNum <= 0.610000){
temporary = 15;
}
// temporary yields zero
答案 0 :(得分:1)
所以:
默认情况下,0.590000是 DOUBLE
所以float tempNum = 0.59000
导致演员。
要证明这一点:
float tempNum = 0.590000f;
int temporary;
if (tempNum >= 0.590000f && tempNum <= 0.610000f){
temporary = 15;
}
所以,请记住:
aaa.aaa 是 DOUBLE
aaa.aaaf FLOAT