Is there any way to print values to more decimal places using fprintf?

82 views (last 30 days)
fprintf('The value claculated for Vo is %f \n',est)

Accepted Answer

Stephen23
Stephen23 on 4 Nov 2021
Edited: Stephen23 on 4 Nov 2021
As the FPRINTF documentation explains, you can specify the number of decimal digits:
est = pi;
fprintf('The value claculated for Vo is %f \n',est)
The value claculated for Vo is 3.141593
fprintf('The value claculated for Vo is %.10f \n',est)
The value claculated for Vo is 3.1415926536
  2 Comments
Stephen23
Stephen23 on 11 Mar 2024
"what if you wanted a specific number of digits before the decimal"
Then you can specify the fieldwidth, e.g. to print a total of 16 characters with leading zeros:
est = pi;
fprintf('The value claculated for Vo is %016.10f \n',est)
The value claculated for Vo is 00003.1415926536

Sign in to comment.

More Answers (0)

Categories

Find more on Dictionaries in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!