How to round up to the next 10

215 ビュー (過去 30 日間)
Stwiwi
Stwiwi 2018 年 9 月 27 日
コメント済み: Gaurav 2025 年 1 月 6 日
Hey, I have the following problem: I want to round up to the next 10. Meaning if I have x=14.5613, I want this to become x=20. I used the following Code:
x=14.5613;
x=round(x,-1);
x=10
To get x=20 I could just do this:
x=round(x,-1)+10
The Problem with this code comes when x is higher than 15. For example
x=18.5613
x=round(x,-1)+10
solves to x=30. So what I am looking for is a rounding function which rounds UP to the next 10 and NOT to the NEAREST. Can anybody help me? That would be awesome:)
  1 件のコメント
Gaurav
Gaurav 2025 年 1 月 6 日
use ceil()

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2018 年 9 月 27 日
編集済み: Adam Danz 2018 年 9 月 27 日
x=14.5613;
xRound = ceil(x/10)*10;
  3 件のコメント
Christine Baniqued
Christine Baniqued 2020 年 8 月 25 日
How do you round off in nearest ten-thousanths?
Adam Danz
Adam Danz 2020 年 8 月 25 日
For simple rounding, without the need to always round up or down, use

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by