Is it possible for matlab to print output numbers like 0.98765432 merely as .987654 with no fronting zero and only six digits (rounded) ?
3 views (last 30 days)
Show older comments
Is it possible for matlab to print output numbers like 0.98765432 merely as .987654 with no fronting zero and only six digits (rounded) ?
1 Comment
dpb
on 15 May 2022
I don't believe that is within the C Standard i/o specification of a formatting string definition, no...it is helpful in that way of writing prettified fields. Believe you would have to post-process the output to do so to replace the "0." with just "." to get there.
Where do you want/need this to occur?
Accepted Answer
Walter Roberson
on 15 May 2022
regexprep(compose("%.6f", YourMatrix), "^0\.", ".")
That would give you a string() array
4 Comments
More Answers (1)
the cyclist
on 15 May 2022
Edited: the cyclist
on 15 May 2022
x = 0.98765432;
s = eraseBetween(sprintf("%7.6f",x),1,1)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!