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

1 vue (au cours des 30 derniers jours)
Baris Can Ayvaz
Baris Can Ayvaz le 15 Mar 2018
How can I write a program that indicates a number if it is integer or not?

Réponses (3)

James Tursa
James Tursa le 15 Mar 2018
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 le 15 Mar 2018
Modifié(e) : Roger Stafford le 15 Mar 2018
If n is your number, then
round(n)==n
is true if and only if n is an integer

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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by