how to use format spec in fprintf properly

11 views (last 30 days)
I have read the help documentation but somtehing doesnt work as expected. say i have a variable
and i want to print to the command window the value of x while allowing 3 digits bedfore the point and 3 after. so i expect to get 003.140 i used
and got
3.140 as output.
what went wrong ? thanks

Accepted Answer

Image Analyst
Image Analyst on 16 Nov 2013
The first number is the total field width, INCLUDING the number after the decimal point. It is not the number before, dot, and then the number after. So if you wanted 3 before, a decimal point, and then 3 more, you'd have to do %7.3f.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by