How to check if a number is integer or not

zakaria -  
teebo Messages postés 33570 Date d'inscription   Statut Modérateur Dernière intervention   -
i want to know to check in a program if the user has entered an enteger number or not
A voir également:

5 réponses

ipl Messages postés 5738 Statut Contributeur sécurité 585
 
Hi zakaria, Blux, hi everyone,

Blux... here you are testing whether a number is even! if your number is 3, the test won't be right as
int(3/2)=1 is not equal to 3/2=1,5 however 3 is an integer !

The true test is:
int(number)=number then number is an integer!

@12C4
Ipl
1
blux Messages postés 1970 Date d'inscription   Statut Modérateur Dernière intervention   3 367
 
yes, you're right...
sorry, I was tired...

A+ Blux            "Les cons, ça ose tout.
C'est même à ça qu'on les reconnait"
0
blux Messages postés 1970 Date d'inscription   Statut Modérateur Dernière intervention   3 367
 
Hello !

if int(number/2)=number/2 then number is integer...

A+ Blux            "Les cons, ça ose tout.
C'est même à ça qu'on les reconnait"
0
WhiteFang Messages postés 2063 Statut Membre 204
 
Hi !!
Try "TypeName" in VB/VBA code (if applicable).... ;-)))
Wild and Free
0
Teebo
 
Well, you test the type, even if it should works, this is not really a thing to do...and our friend didn't tell whcih langage he was using...bad boy ;-)))
0
Pierre Fauconnier
 
hello

int(100000)=100000 is right, but 100000 is not an integer, but a long...
0
teebo Messages postés 33570 Date d'inscription   Statut Modérateur Dernière intervention   1 793
 
Well, depends what you call an integer, when I was a child I learned at school that 351458486956136896548746584 was an integer as well as 1...
Why should computer change the tausends years old reality?

ö,ö  "Il est plus facile de donner des conseils
\_/    que de les appliquer"
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jojo
 
Pierre Fauconnier is rigth.
if(int(nb)=nb && nb <257) is an integer(signed)
:-))
0
teebo Messages postés 33570 Date d'inscription   Statut Modérateur Dernière intervention   1 793
 
Why do you automaticaly switch to the computer defined integer, use a dictionnary!

ö,ö  "Il est plus facile de donner des conseils
\_/    que de les appliquer"
0