フィルターのクリア

error while converting to string

5 ビュー (過去 30 日間)
Indrani
Indrani 2023 年 8 月 25 日
移動済み: Walter Roberson 2023 年 8 月 25 日
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?

採用された回答

Stephen23
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)
s = "08"
  1 件のコメント
Indrani
Indrani 2023 年 8 月 25 日
移動済み: Walter Roberson 2023 年 8 月 25 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by