How do I differentiate between integer and floating point numbers in a double array?

13 vues (au cours des 30 derniers jours)
My requirement is to import data from Excel which has both integer and floating point numbers. For example, 1 and 2.5 I want to differentiate between them. But the Excel import coverts all numeric data into 'double' which is floating point by default.
Any help in this regard is appreciated! Thanks!
  1 commentaire
José-Luis
José-Luis le 15 Jan 2014
What makes you think 1 is stored as an integer? It might very well be a double.

Connectez-vous pour commenter.

Réponse acceptée

José-Luis
José-Luis le 15 Jan 2014
is_integer = your_data == floor(your_data);
  2 commentaires
Shubha
Shubha le 15 Jan 2014
isinteger(floor(2.3)) also returns a 0. So how is it possible to differentiate integers from floating point numbers then?
Shubha
Shubha le 15 Jan 2014
Oh yeah now I get it if (my_data==floor(my_data)) 'Its an integer' else 'Its a floating point value' end This works well! Thanks for the help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by