why does the output show % when i type fprintf('%%')

 Respuesta aceptada

Star Strider
Star Strider el 17 de Mzo. de 2022

0 votos

In the documentation section on formatSpec see the section on Text Before or After Formatting Operators.

4 comentarios

r=99
fprintf('%d%%',r)
so when i type this i get 99%. So it's(%%) use is only to print or show percent
Star Strider
Star Strider el 17 de Mzo. de 2022
Yes.
The ‘%’ sign is a format operator for fprintf (and similar functions) so in order to print it as a percent sign, it must be ‘escaped’ by using .'%%'. Similarly, in order to print a ‘\’ it is necessary to ‘escape’ it as well '\\'. See the documentation section I linked to for a full discussion of all of them.
Sanjay N
Sanjay N el 17 de Mzo. de 2022
Editada: Sanjay N el 17 de Mzo. de 2022
Thank you
Star Strider
Star Strider el 17 de Mzo. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 17 de Mzo. de 2022

Comentada:

el 17 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by