How do you get a specific decimal accuracy with the fprintf function?

8 ビュー (過去 30 日間)
Ashlianne Sharma
Ashlianne Sharma 2021 年 4 月 20 日
コメント済み: Ashlianne Sharma 2021 年 4 月 20 日
I want to display my r variable with 6 decimals, but I am not sure how to format the line. I could not really find how to with the documentation page and would appreciate some guidance, Thank you so much!!
fprintf("The estimated principle stress val is %6f .\n " + r )
  1 件のコメント
Ashlianne Sharma
Ashlianne Sharma 2021 年 4 月 20 日
I know you can do format long, but I want it to be specifically 6 decimals.

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

採用された回答

the cyclist
the cyclist 2021 年 4 月 20 日
編集済み: the cyclist 2021 年 4 月 20 日
Your r variable needs to be a second argument (not using a plus sign as you did).
r = pi;
fprintf("The estimated principle stress val is %9.6f.\n ",r)
The estimated principle stress val is 3.141593.
The %9.6f indicates that the output should use 6 decimal places, and field width of 9.
  1 件のコメント
Ashlianne Sharma
Ashlianne Sharma 2021 年 4 月 20 日
okay that's awesome! thank you for your help!

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

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by