How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?
101 次查看(过去 30 天)
显示 更早的评论
I would like to print a string containing the '%' character. However, when I attempt the following:
sprintf('100%')
The output reads:
100
采纳的回答
MathWorks Support Team
2009-6-27
To escape the percent symbol, use two percent signs. For example:
sprintf('100%%')
Yields the output:
100%
1 个评论
Walter Roberson
2017-11-23
str2write = '% whatever 75% ';
str2write = regexprep( str2write, '%', '%%' );
or
str2write = '% whatever 75% ';
str2write = strrep( str2write, '%', '%%' );
更多回答(1 个)
Walter Roberson
2017-11-23
sprintf('%s', '100%')
The % are only "eaten" if they occur in the first parameter, the format position.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!