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

 採用された回答

Star Strider
Star Strider 2022 年 3 月 17 日

0 投票

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

4 件のコメント

Sanjay N
Sanjay N 2022 年 3 月 17 日
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 2022 年 3 月 17 日
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 2022 年 3 月 17 日
編集済み: Sanjay N 2022 年 3 月 17 日
Thank you
Star Strider
Star Strider 2022 年 3 月 17 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by