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

I would like to display a number with only two digits after the decimal point in MATLAB.

댓글 수: 2

What is the relation to the tag "digital signal processing"? Can you explain any details concerning the question, please?
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

댓글을 달려면 로그인하십시오.

 채택된 답변

추가 답변 (4개)

masoud sistaninejad
masoud sistaninejad 2020년 12월 30일
format shortg
y = 3.3333333333333333333333333333333333333
y_out = round(y,2)
Mardhika Jenned
Mardhika Jenned 2011년 3월 3일
example
10/3 = 3.3333
but
i want to change 3.3333 to 4.
how the formula. please tell me, thx
For the specific case of 2 decimal places (does not work for any other number)
format bank
10/3
ans =
3.33

댓글 수: 4

Thanks. I'm teaching a financial computing course and was looking for banker's output :-)
Be careful about rounding vs truncation. I do not know what is standard for banking purposes.
in the same scenario, could you please tell how to obtain 03.33??
x = 10/3;
sprintf('%05.2f', x)
ans = '03.33'
compose("%05.2f", x)
ans = "03.33"
num2str(x, '%05.2f')
ans = '03.33'

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2011년 3월 3일

댓글:

2021년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by