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

1,785 views (last 30 days)
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 CommentsShowHide 1 older comment
Mardhika Jenned on 3 Mar 2011
i'm sorry, i don't understand about tags, so i pick a random,
i mean this
10/3 = 3.3333333333333333333333333333333333333
i just want matlab show 3.333
thx

Jan on 3 Mar 2011
Display a number with two digits behind the dot:
fprintf('%.2f', pi)
Rodel Consuelo on 24 Nov 2020
thankyou

masoud sistaninejad on 30 Dec 2020
format shortg
y = 3.3333333333333333333333333333333333333
y_out = round(y,2)

Mardhika Jenned on 3 Mar 2011
thx

Mardhika Jenned on 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 on 3 Mar 2011
ceil(10/3)

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
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'

### Categories

Find more on Logical in Help Center and File Exchange

### Tags

No tags entered yet.

### Community Treasure Hunt

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

Start Hunting!