作者:
m3gl4a (m3gl4)
2015-05-15 21:34:33我自己嘗試寫他的問題看看
public class doublebug {
public static void main(String[] args) {
double x=0.5-0.3,y=0.3-0.1;
if(x==y)
System.out.println("x=y");
else
System.out.println("x=/=y");
}
}
居然是
x=0.2
y=0.19999999999999998
在人去看無疑是x=y 可是電腦是x=/=y
這到底是什麼魔術
作者: jengjye (建) 2015-05-18 01:11:00
用2進位表示10進位的問題,這應該是在計概或計組中就會解答的.....感覺不適合在java中提出來