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!