public class FloatTest {
public static void main(String[] args){
float a = 0.0f;
for(int i=0; i<10; i++){
a+=0.1f;
}
if(a==1.0f){
System.out.println("yse");
}
else
System.out.println(a);
}
}
上面的例子十分有意思。一般我们容易认为输出的果应该为yes,但是其实不然。在程序中浮点数都是近似数,而不是准确值。