Effacer les filtres
Effacer les filtres

error while converting to string

2 vues (au cours des 30 derniers jours)
Indrani
Indrani le 25 Août 2023
Déplacé(e) : Walter Roberson le 25 Août 2023
m = 08
When I am converting the above statement to string by using
string(m)
m becomes 8. However, I want the value of m to remain 08.
Can you help me out?

Réponse acceptée

Stephen23
Stephen23 le 25 Août 2023
Déplacé(e) : Walter Roberson le 25 Août 2023
"However, I want the value of m to remain 08."
Numeric data classes do not store formatting information e.g. how many leading zeros. So asking for the zero to "remain" does not make any sense, because something that is not there cannot "remain". But you can easily specify the leading zeros when you convert to text:
m = 8;
s = sprintf("%02u",m)
s = "08"
  1 commentaire
Indrani
Indrani le 25 Août 2023
Déplacé(e) : Walter Roberson le 25 Août 2023
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings 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!

Translated by