How to remove decimal??

74 visualizaciones (últimos 30 días)
baby
baby el 12 de Mayo de 2012
Comentada: Dyuman Joshi el 20 de Nov. de 2025 a las 14:53
Hello,,
i wanna know how to remove decimal??
Example a = 2.0000
how to remove zero beside point so it will be a = 2??
please help me
  1 comentario
Oleg Komarov
Oleg Komarov el 12 de Mayo de 2012
Note that a is most likely not exactly 2, so the question is, do you want to "display" only the integer part or do you want to "drop" the decimal?

Iniciar sesión para comentar.

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 12 de Mayo de 2012
To make it clear:
a = 2.00000000001
a =
2.0000
Displaying the integer part ( ans is a char), but a retains the fraction:
sprintf('%.f',a)
ans =
2
Dropping the fraction ( ans is same class as a):
fix(a)
ans =
2

Más respuestas (1)

Fabio
Fabio el 12 de Mayo de 2012
As Oleg says if you want to 'display' the integer part just cast to String with num2Str() function: http://www.mathworks.it/help/techdoc/ref/num2str.html
If you want to drop the decimal part you can use round() function: http://www.mathworks.it/help/techdoc/ref/round.html
  8 comentarios
Walter Roberson
Walter Roberson el 19 de Nov. de 2025 a las 20:07
Dyuman Joshi
Dyuman Joshi el 20 de Nov. de 2025 a las 14:53
Is it possible that @Luisa wanted to vote on @Walter's response?

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by