function rem issue with exact result

조회 수: 5 (최근 30일)
shahriar memaran
shahriar memaran 2017년 2월 27일
편집: Stephen23 2017년 2월 27일
sometimes the function rem does not return the exact solution. For example rem(135.01,100) does not return 35.01 but it returns 35.009999999999991 (visible when format is changed to long). Can anyone tel me why !? and how to fix it !?
  댓글 수: 1
Stephen23
Stephen23 2017년 2월 27일
편집: Stephen23 2017년 2월 27일
The decimal value 135.01 cannot be stored exactly in binary, just in the same way that 1/3 cannot be written exactly using decimal digits. Have a look at it in more detail:
>> fprintf('%.30f\n',135.01)
135.009999999999990000000000000000
Read Steven Lord's answer, it tells you what is going on.

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

채택된 답변

Steven Lord
Steven Lord 2017년 2월 27일

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by