JUST Take integer value number from decimal value

조회 수: 257 (최근 30일)
Exton
Exton 2012년 11월 6일
댓글: John D'Errico 2020년 11월 3일
if my output is a decimal value but i just want to take the integer value only
HOW am i going to do that>???
eg
a=4.321323
i just want take 4 , what code should i write??

채택된 답변

José-Luis
José-Luis 2012년 11월 6일
a = -3.1145
your_val = fix(a)
If you also want it to work for negative numbers.

추가 답변 (1개)

Thomas
Thomas 2012년 11월 6일
a=4.321323;
out=floor(a)
  댓글 수: 1
John D'Errico
John D'Errico 2020년 11월 3일
@Rokeya Mumtahana Mou:
If you have a different question , then ask it as a question of your own.
However, there are several functions you should read about.
round: rounds to the nearest integer.
floor: round down toward -inf
fix: round towards zero
ceil: round upwards
You want either ceil or round, depending on the behavior you wish to see. Thus, would 4.49 map to 5, or to 4? ceil would produce always the larger integer, whereas round find the nearest integer.
And of course, fix and floor are identical for positive numbers.

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

카테고리

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