Equation is correct but logically false???

조회 수: 4 (최근 30일)
Florent Dueme
Florent Dueme 2017년 12월 9일
댓글: Star Strider 2017년 12월 10일
Hi all,
I can´t make any sense of this. I have this very simple equation that is equal to 0.1 according to Matlab itself. Yet when I try to create an if statement where something happens if the value is equal to 0.1 Matlab tells me the statement is logically false:
>> a = 11
a =
11
>> (a/10)-(floor(a/10))
ans =
0.1000
>> (a/10)-(floor(a/10))==0.1
ans =
logical
0
Even weirder, it works fine when the equation equals another number like 0.6 or 0.7 (but not 0.2 or 0.3).
Any help understanding this would be very welcome!
  댓글 수: 2
Florent Dueme
Florent Dueme 2017년 12월 10일
Thanks a lot for the links and sorry for the boring question! Wasn´t sure what to look for as I didn´t know it was a floating-point numbers issue.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 12월 9일
This is one of the better discussions on the problem you are experiencing: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? (link).
  댓글 수: 2
Florent Dueme
Florent Dueme 2017년 12월 10일
Thanks!
Star Strider
Star Strider 2017년 12월 10일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!