Rounding a decimal down

4 Ansichten (letzte 30 Tage)
L'O.G.
L'O.G. am 2 Dez. 2022
Kommentiert: Vilém Frynta am 3 Dez. 2022
With round(x,2) I can round a number to the nearest hundredth, but how do I round down to the nearest hundredth? For example, both 0.143 and 0.147 should become 0.14.

Akzeptierte Antwort

Matt J
Matt J am 2 Dez. 2022
Bearbeitet: Matt J am 2 Dez. 2022
x=0.147;
floor(x*100)/100
ans = 0.1400

Weitere Antworten (2)

Les Beckham
Les Beckham am 2 Dez. 2022
x = [0.143 0.147];
floor(x*100)/100
ans = 1×2
0.1400 0.1400

Vilém Frynta
Vilém Frynta am 2 Dez. 2022
Bearbeitet: Vilém Frynta am 2 Dez. 2022
Example:
X = 0.143;
Y = sprintf('%.2f',X);
Y = str2double(Y)
Y = 0.1400
Someone ahd same question before. Next time, try to Google your question before asking.
  2 Kommentare
Vilém Frynta
Vilém Frynta am 3 Dez. 2022
True, I just reffered to someone else's answer.

Melden Sie sich an, um zu kommentieren.

Kategorien

Find more on Agriculture in Help Center and File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by