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

 Réponse acceptée

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

1 commentaire

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

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Version

R2008b

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by