Why the answer is 10.

조회 수: 11 (최근 30일)
Nilotpaul Kundu
Nilotpaul Kundu 2022년 1월 30일
댓글: DGM 2022년 1월 30일
Why the answer is 10. Shouldn't it be 11?
format long;
y = (3.8 - 1.6)/0.2;
x = floor(y);
disp(x);
  댓글 수: 1
Arif Hoq
Arif Hoq 2022년 1월 30일
편집: Arif Hoq 2022년 1월 30일
>> (3.8 - 1.6)/0.2
ans =
10.999999999999998
Floor rounds each element of a vector/matrix to the nearest integer less than or equal to that element. so the floor value of y would be 10.
If you use "round" function it will show the value 11.
format long;
y = (3.8 - 1.6)/0.2;
x = round(y);
disp(x);
for more information please type in the command prompt.
doc round
doc floor

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

답변 (1개)

KSSV
KSSV 2022년 1월 30일
If you want 11 use ceil.
y = (3.8 - 1.6)/0.2;
x = ceil(y);
disp(x);
11
Alos have a look on functions round, fix.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by