Why isn't 95.77-95.68 = exactly 0.09?
1 回表示 (過去 30 日間)
古いコメントを表示
I guess I expected 95.77-95.68 to be exactly 0.09, just as I expected 3*(1/3) to be 0.9999999999, but I was wrong on both! More importantly, how can I get it be rounded off to 0.09? I could use round() or mod(diff*100)/100
0 件のコメント
採用された回答
Walter Roberson
2018 年 3 月 7 日
>> fprintf('%.999g\n', 95.77, 95.68, 95.77-95.68)
95.7699999999999960209606797434389591217041015625
95.68000000000000682121026329696178436279296875
0.0899999999999891997504164464771747589111328125
>> fprintf('%.999g\n', 1/3)
0.333333333333333314829616256247390992939472198486328125
>> isAlways(1-sym('0.333333333333333314829616256247390992939472198486328125')*3 < eps)
ans =
logical
1
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!