How can I display a number with only two digits after the decimal point in MATLAB?

702 vues (au cours des 30 derniers jours)
I would like to display a number with only two digits after the decimal point in MATLAB.
  2 commentaires
Jan
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
Mardhika Jenned le 3 Mar 2011
i'm sorry, i don't understand about tags, so i pick a random,
about the question,
i mean this
10/3 = 3.3333333333333333333333333333333333333
i just want matlab show 3.333
sorry my english is bad,
thx

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 3 Mar 2011
Display a number with two digits behind the dot:
fprintf('%.2f', pi)

Plus de réponses (4)

masoud sistaninejad
masoud sistaninejad le 30 Déc 2020
format shortg
y = 3.3333333333333333333333333333333333333
y_out = round(y,2)

Mardhika Jenned
Mardhika Jenned le 3 Mar 2011
thx

Mardhika Jenned
Mardhika Jenned le 3 Mar 2011
example
10/3 = 3.3333
but
i want to change 3.3333 to 4.
how the formula. please tell me, thx

Walter Roberson
Walter Roberson le 31 Déc 2020
For the specific case of 2 decimal places (does not work for any other number)
format bank
10/3
ans =
3.33
  4 commentaires
Megha
Megha le 16 Sep 2021
in the same scenario, could you please tell how to obtain 03.33??
Walter Roberson
Walter Roberson le 16 Sep 2021
x = 10/3;
sprintf('%05.2f', x)
ans = '03.33'
compose("%05.2f", x)
ans = "03.33"
num2str(x, '%05.2f')
ans = '03.33'

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by