How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?

I would like to print a string containing the '%' character. However, when I attempt the following:
sprintf('100%')
The output reads:
100

 Accepted Answer

To escape the percent symbol, use two percent signs. For example:
sprintf('100%%')
Yields the output:
100%

1 Comment

str2write = '% whatever 75% ';
str2write = regexprep( str2write, '%', '%%' );
or
str2write = '% whatever 75% ';
str2write = strrep( str2write, '%', '%%' );

Sign in to comment.

More Answers (1)

sprintf('%s', '100%')
The % are only "eaten" if they occur in the first parameter, the format position.

Categories

Products

Release

R2008b

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!