error while converting to string
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Stephen23
2023-8-25
移动:Walter Roberson
2023-8-25
"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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!