フィルターのクリア

How do I shorten the amount of decimal spaces in a fprintf statement?

7 ビュー (過去 30 日間)
Matthew Olivo
Matthew Olivo 2018 年 1 月 15 日
コメント済み: Star Strider 2018 年 1 月 15 日
I type in:
fprintf('The final student score is %f\n',round(final_points,1))
and the answer it gives me is:
The final student score is 690.200000
I need this to be shortened to 690.2, but cant figure out how. Please and thank you!

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 15 日
Instead of %f use %.1f

その他の回答 (1 件)

Star Strider
Star Strider 2018 年 1 月 15 日
Use the format descriptor: '%.1f' to get one decimal place.
See the documentaion on FormatSpec (link) for a full description of all the options.
  2 件のコメント
Matthew Olivo
Matthew Olivo 2018 年 1 月 15 日
Thank you!!
Star Strider
Star Strider 2018 年 1 月 15 日
My pleasure!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by