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***

采纳的回答

madhan ravi
madhan ravi 2018-10-12
编辑:madhan ravi 2018-10-12
xstar=sprintf('%.2f%s',round(x,3,'significant'),star)

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018-10-12
x=1.361620214248647;
star='***';
xstar=sprintf('%f%s',round(x,3,'significant'),star)
  2 个评论
gsourop
gsourop 2018-10-12
Hi there,
Thank you for answering my question. Nevertheless, the answer I get 1.360000***, but I would expect 1.36***, instead.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by