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!