How to format the integer value with leading zeros in matlab?

前端 未结 2 1562
攒了一身酷
攒了一身酷 2021-01-20 19:41

I want format integer value by adding leading zeros and display it as string. For example, I have 3 and I want to display it as 003. I want to do i

相关标签:
2条回答
  • 2021-01-20 20:22

    Use sprintf():

    aa = sprintf('%03d', 3); % aa will be 003
    

    Note that aa here is a string. Check out its documentation for more info.

    0 讨论(0)
  • Note that you can also use string formatting in num2str command as well:

    num2str( 3, '%03d' );
    
    0 讨论(0)
提交回复
热议问题