How to reduce precision of digit after decimal point? Matlab (R2020a)
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
taimour sadiq
am 23 Okt. 2020
Kommentiert: Ameer Hamza
am 10 Dez. 2020
if i have
a = 1.2345 or
a = 22.34325 or
a = 334.659809832
i want to reduce precision after decimal point to two digit so results should be
a= 1.23
a = 22.34
a = 334.65
i have tried ceil,floor, vpa, round(a,2) but this doesnt give me the above required result... i have searched the matlab answer mostly old questions replied with "fprintf which may support older versions. Kidly Guide
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 23 Okt. 2020
Bearbeitet: Ameer Hamza
am 23 Okt. 2020
If you are only concerned with displaying the results with two digits after the decimal, then you can use fprintf
a = 334.659809832
fprintf('a=%.2f\n', a)
13 Kommentare
Weitere Antworten (1)
Mathieu NOE
am 23 Okt. 2020
hi
dirty trick , example to round to 2 digits after decimal :
aa = 0.01*round(a*100)
example :
0.01*round(pi*100)
ans =
3.1400
or when you convert to string :
disp(num2str(pi,3))
3.14
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!