A rounding problem that falls under ceil and round

1 vue (au cours des 30 derniers jours)
SETH GERSBACH le 20 Mar 2022
Commenté : SETH GERSBACH le 20 Mar 2022
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);
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

AndresVar le 20 Mar 2022
Modifié(e) : AndresVar le 20 Mar 2022
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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
SETH GERSBACH le 20 Mar 2022
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Electrical Block Libraries dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by