How to make num2str output with 4 digits left of decimal? eg 0-> 0000
Show older comments
I am trying to get num2str to fomat its output with 4 digits. For example num2str(0) -> '0000' or num2str(125)-> '0125'
I know that there is a way to do this for digits after the decimal but I'm not sure how to do it for digits before the decimal.
Accepted Answer
More Answers (1)
the cyclist
on 7 Apr 2017
Edited: the cyclist
on 7 Apr 2017
sprintf('%04d',125)
or
sprintf('%04d',0)
The formatting specification is pretty versatile, but can take a little while to become facile with.
Categories
Find more on Numeric Types 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!