How can I cut four numbers after the decimal number without rounding using MATLAB ?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad Salem
am 3 Dez. 2023
Kommentiert: Walter Roberson
am 4 Dez. 2023
I have a number like this:
2.32166873546944
I want to take only four numbers after the decimal point and without rounding, that is, I only want:
2.3216
How do I do this in Matlab ?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 3 Dez. 2023
Bearbeitet: John D'Errico
am 3 Dez. 2023
You want to truncate after the 4th decimal place? Easy peasy.
You shift where the decimal place lies, then use floor.
format long g
x = 2.32166873546944
y = floor(x*10000)/10000
2 Kommentare
Walter Roberson
am 4 Dez. 2023
If you want "four digits after the decimal place" you should probably use fix() instead of floor()
format long g
x = 2.32166873546944
xn = -x
y1 = floor(x*10000)/10000
y2 = fix(x*100000)/100000
y3 = floor(xn*10000)/10000
y4 = fix(xn*10000)/10000
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!