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!