필터 지우기
필터 지우기

How to remove decimal??

조회 수: 19 (최근 30일)
baby
baby 2012년 5월 12일
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
Oleg Komarov
Oleg Komarov 2012년 5월 12일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 5월 12일
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

추가 답변 (1개)

Fabio
Fabio 2012년 5월 12일
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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by