how to manage Fraction format problem

Dear all, I have vector with numbers and fraction. How can I reduce fraction number.?for example a=[1.23456789 6.14521456 7.906342678 10.47609352]
expect results should be: re=[ 1.2 6.1 7.9 10.4] Thanks...

 Respuesta aceptada

the cyclist
the cyclist el 30 de En. de 2017
Editada: the cyclist el 30 de En. de 2017
One way to display a decimal number to one decimal place:
sprintf('%5.1f',a)
Note that this will not change the value stored in a; it will only display it differently.

3 comentarios

skysky2000
skysky2000 el 30 de En. de 2017
Thanks the cyclist,,,, when I make it as below, showed me as 1 cell not vector: re=sprintf('%5.1f',a);
the cyclist
the cyclist el 30 de En. de 2017
Editada: the cyclist el 30 de En. de 2017
If you want to store a value that is changed, use the round function:
re = round(a,1)
Or you might want fix instead.
skysky2000
skysky2000 el 30 de En. de 2017
That amazing 100% work..... thanks alots

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 30 de En. de 2017

0 votos

See the second input of the round function.

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de En. de 2017

Comentada:

el 30 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by