필터 지우기
필터 지우기

error while converting to string

조회 수: 2 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by