Round down and Round up?
古いコメントを表示
Hi everyone,
I have two numbers and want to round up and round down them.
minval = 0.4410 and maxval=0.8450
I want to round down the first number and it will be 0.4. The 2nd number after being rounded up will be 0.9.
I tried with floor(minval) it returns 0 and ceil(maxval) it returns 1. Those numbers are not the result I want.
Could someone give me some advice?
I'm using MATLAB R2014a.
Thank you so much.
1 件のコメント
shaadinama
2023 年 5 月 8 日
編集済み: DGM
2023 年 5 月 11 日
In MATLAB, the functions "floor" and "ceil" can be used to round down and round up, respectively.
The "floor" function rounds a given input value down to the nearest integer. For example, "floor(3.7)" would return 3, and "floor(-2.3)" would return -3.
The "ceil" function, on the other hand, rounds a given input value up to the nearest integer. For example, "ceil(3.2)" would return 4, and "ceil(-2.9)" would return -2.
Both functions can be useful in various mathematical and programming contexts where it is necessary to round numbers to the nearest whole integer.
採用された回答
その他の回答 (1 件)
- floor(minval*10)/10
- ceil(maxval*10)/10
1 件のコメント
+1 This actually returns what the OP requested:
minval = 0.4410;
maxval = 0.8450;
floor(minval*10)/10
ceil(maxval*10)/10
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!