How can I format a percent using 2 digits after the decimal
30 ビュー (過去 30 日間)
古いコメントを表示
I have what should be a percentage but it comes up with several decimal places, how can I limit to 2 after the decimal
0 件のコメント
回答 (2 件)
Geoff
2012 年 3 月 13 日
If you want to do it without using strings:
round(x * 100) / 100;
One reason you might want to do that is if you have a whole matrix of percentages and want to quickly show them in a sensible way, without messing with the output format for other numbers.
-g-
0 件のコメント
Oleg Komarov
2012 年 3 月 13 日
Example:
x = 0.78765645; % almost 78.8%
sprintf('%0.2f',x)
ans =
0.79
Is this the effect you're trying to accomplish?
2 件のコメント
Image Analyst
2012 年 3 月 13 日
By the way, the 0 is not necessary. I always just use sprintf('%.2f',x)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!