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

 Accepted Answer

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

what if you wanted a specific number of digits before the decimal
"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

Tags

Community Treasure Hunt

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

Start Hunting!