Is there any way to print values to more decimal places using fprintf?

68 ビュー (過去 30 日間)
Joshua Ekwueme
Joshua Ekwueme 2021 年 11 月 4 日
コメント済み: Stephen23 2024 年 3 月 11 日
fprintf('The value claculated for Vo is %f \n',est)

採用された回答

Stephen23
Stephen23 2021 年 11 月 4 日
編集済み: Stephen23 2021 年 11 月 4 日
As the FPRINTF documentation explains, you can specify the number of decimal digits:
est = pi;
fprintf('The value claculated for Vo is %f \n',est)
The value claculated for Vo is 3.141593
fprintf('The value claculated for Vo is %.10f \n',est)
The value claculated for Vo is 3.1415926536
  2 件のコメント
Cecilia
Cecilia 2024 年 3 月 11 日
what if you wanted a specific number of digits before the decimal
Stephen23
Stephen23 2024 年 3 月 11 日
"what if you wanted a specific number of digits before the decimal"
Then you can specify the fieldwidth, e.g. to print a total of 16 characters with leading zeros:
est = pi;
fprintf('The value claculated for Vo is %016.10f \n',est)
The value claculated for Vo is 00003.1415926536

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDictionaries についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by