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 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2022 年 1 月 30 日

コメント済み:

DGM
2022 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by