How can I write a program that indicates a number if it is integer or not?

조회 수: 1 (최근 30일)
Baris Can Ayvaz
Baris Can Ayvaz 2018년 3월 15일
답변: Star Strider 2018년 3월 15일
How can I write a program that indicates a number if it is integer or not?

답변 (3개)

James Tursa
James Tursa 2018년 3월 15일
doc floor
doc ceil
doc round
What happens if you use one of these functions and compare the result to the original value?

Roger Stafford
Roger Stafford 2018년 3월 15일
편집: Roger Stafford 2018년 3월 15일
If n is your number, then
round(n)==n
is true if and only if n is an integer

Star Strider
Star Strider 2018년 3월 15일
Use the rem (link) or mod (linked to in that page) functions.
isint = @(x) rem(x,1) == 0;
It returns a logical result.

카테고리

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