A rounding problem that falls under ceil and round

조회 수: 8 (최근 30일)
SETH GERSBACH
SETH GERSBACH 2022년 3월 20일
댓글: SETH GERSBACH 2022년 3월 20일
I would like to round a number up to the nearest 100 place
i.e
x = 20
y = round(x)
y = 100
I'm doing this to record the maximun possible value, I know ceil will always round up but I can't set it to a set value
here is the current code
distance = 50; % Distance the package will travel (Km)
distnace_check = round(distance,-2);

채택된 답변

AndresVar
AndresVar 2022년 3월 20일
편집: AndresVar 2022년 3월 20일
How about
x=[0 20 50 100 101 900 901 1234]; % test numbers
y = ceil(x/100)*100
y = 1×8
0 100 100 100 200 900 1000 1300
  댓글 수: 1
SETH GERSBACH
SETH GERSBACH 2022년 3월 20일
Thank you, it does work and I now understand how.
By dividing the value by 100, it then ceil makes the value below a decimal point to round up to the desired value before converting back to the 100 place.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by