How to concatenate the rounded digits of a number and a string?
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    gsourop
 el 12 de Oct. de 2018
  
    
    
    
    
    Comentada: Stephen23
      
      
 el 12 de Oct. de 2018
            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 comentarios
  Stephen23
      
      
 el 12 de Oct. de 2018
				Why so complex? sprintf does rounding for you:
>> sprintf('%.2f%s',x,star)
ans =
1.36***
Respuesta aceptada
  madhan ravi
      
      
 el 12 de Oct. de 2018
        
      Editada: madhan ravi
      
      
 el 12 de Oct. de 2018
  
      xstar=sprintf('%.2f%s',round(x,3,'significant'),star)
0 comentarios
Más respuestas (1)
  KALYAN ACHARJYA
      
      
 el 12 de Oct. de 2018
        x=1.361620214248647;
star='***';
xstar=sprintf('%f%s',round(x,3,'significant'),star)
2 comentarios
  KALYAN ACHARJYA
      
      
 el 12 de Oct. de 2018
				x=1.361620214248647;
star='***';
xstar=sprintf('%.2f%s',round(x,2),star)
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



