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
Jan
2011년 3월 3일
What is the relation to the tag "digital signal processing"? Can you explain any details concerning the question, please?
Mardhika Jenned
2011년 3월 3일
채택된 답변
추가 답변 (4개)
masoud sistaninejad
2020년 12월 30일
4 개 추천
format shortg
y = 3.3333333333333333333333333333333333333
y_out = round(y,2)
For the specific case of 2 decimal places (does not work for any other number)
format bank
10/3
댓글 수: 4
Omar Lakkis
2021년 9월 15일
Thanks. I'm teaching a financial computing course and was looking for banker's output :-)
Walter Roberson
2021년 9월 15일
Be careful about rounding vs truncation. I do not know what is standard for banking purposes.
Megha
2021년 9월 16일
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')
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!