How to convert number to string with fixed length?
54 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Juan Moreno
le 4 Déc 2020
Réponse apportée : Asad (Mehrzad) Khoddam
le 4 Déc 2020
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 commentaires
Réponse acceptée
Asad (Mehrzad) Khoddam
le 4 Déc 2020
You can use sprintf
s=sprintf('%05d',124);
disp(s);
%05d means that you have leading zeros and the total length 0f 5
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!