How to concatenate the rounded digits of a number and a string?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I am trying to concatenate a rounded number (in the 2nd digit after decimal) and string value, so that:
x= 1.361620214248647
star = '***'
xstar = sprintf('%d%s',round(x,3,'significant'), star)
I would expect the output to be 1.36***, rather than 1.360000e+00***
댓글 수: 2
Stephen23
2018년 10월 12일
Why so complex? sprintf does rounding for you:
>> sprintf('%.2f%s',x,star)
ans =
1.36***
채택된 답변
madhan ravi
2018년 10월 12일
편집: madhan ravi
2018년 10월 12일
xstar=sprintf('%.2f%s',round(x,3,'significant'),star)
댓글 수: 0
추가 답변 (1개)
KALYAN ACHARJYA
2018년 10월 12일
x=1.361620214248647;
star='***';
xstar=sprintf('%f%s',round(x,3,'significant'),star)
댓글 수: 2
KALYAN ACHARJYA
2018년 10월 12일
x=1.361620214248647;
star='***';
xstar=sprintf('%.2f%s',round(x,2),star)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!