How do I change the number of decimal places my output has
4 views (last 30 days)
Show older comments
I need to run a program so it shows no decimal places. I also need to run it again with showing one decimal place
1 Comment
James Tursa
on 17 Jan 2017
Please show some examples for input & desired output. Do you want the data clipped or rounded etc, or do you just want the display of the numbers to be a certain way?
Answers (1)
Walter Roberson
on 17 Jan 2017
So like this:
value = sqrt(pi);
for numplaces = 0 : 5
fprintf('%.*f\n', numplaces, value);
end
Note: this rounds the values to the appropriate number of decimal places.
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!