MATLAB Answers

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

1.722 views (last 30 days)
Mardhika Jenned
Mardhika Jenned on 3 Mar 2011
Commented: Walter Roberson on 16 Sep 2021
I would like to display a number with only two digits after the decimal point in MATLAB.
  2 Comments
Mardhika Jenned
Mardhika Jenned on 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

Sign in to comment.

More Answers (4)




Walter Roberson
Walter Roberson on 31 Dec 2020
For the specific case of 2 decimal places (does not work for any other number)
format bank
10/3
ans =
3.33
  4 Comments
Walter Roberson
Walter Roberson on 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'

Sign in to comment.

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by