How can I display a number with only two digits after the decimal point in MATLAB?
Afficher commentaires plus anciens
I would like to display a number with only two digits after the decimal point in MATLAB.
2 commentaires
Jan
le 3 Mar 2011
What is the relation to the tag "digital signal processing"? Can you explain any details concerning the question, please?
Mardhika Jenned
le 3 Mar 2011
Réponse acceptée
Plus de réponses (4)
masoud sistaninejad
le 30 Déc 2020
4 votes
format shortg
y = 3.3333333333333333333333333333333333333
y_out = round(y,2)
Mardhika Jenned
le 3 Mar 2011
0 votes
For the specific case of 2 decimal places (does not work for any other number)
format bank
10/3
4 commentaires
Omar Lakkis
le 15 Sep 2021
Thanks. I'm teaching a financial computing course and was looking for banker's output :-)
Walter Roberson
le 15 Sep 2021
Be careful about rounding vs truncation. I do not know what is standard for banking purposes.
Megha
le 16 Sep 2021
in the same scenario, could you please tell how to obtain 03.33??
x = 10/3;
sprintf('%05.2f', x)
compose("%05.2f", x)
num2str(x, '%05.2f')
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!