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

조회 수: 2 (최근 30일)
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.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by