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

12 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Jan. 2018
Instead of %f use %.1f

Weitere Antworten (1)

Star Strider
Star Strider am 15 Jan. 2018
Use the format descriptor: '%.1f' to get one decimal place.
See the documentaion on FormatSpec (link) for a full description of all the options.

Community Treasure Hunt

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

Start Hunting!

Translated by