How to convert number to string with fixed length?
조회 수: 58 (최근 30일)
이전 댓글 표시
I need to convert an integer into a string with 4 digits; I mean if the number is 4, I need "0004", if the number is 360, I need "0360", and so on. The string function doesn't work for this. I would like to do it without using the if statement. Thank you.
댓글 수: 0
채택된 답변
Asad (Mehrzad) Khoddam
2020년 12월 4일
You can use sprintf
s=sprintf('%05d',124);
disp(s);
%05d means that you have leading zeros and the total length 0f 5
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!