How to pad zeros in the front of the number using 'num2str'

608 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Aug 2016
For example, you have 47 and you want the output to be 047
Please use the following command:
>> num = 47;
>> num2str(num,'%03.f');
The '%03.f' format specifier indicates that there would totally 3 digits before the decimal point prepended with 0 depending on the digits in the number.
 

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!