How to check if a number is integer or not

zakaria -  
teebo Messages postés 33585 Date d'inscription   Statut Contributeur Dernière intervention   -
i want to know to check in a program if the user has entered an enteger number or not

5 réponses

  1. 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
    1. blux Messages postés 5035 Date d'inscription   Statut Modérateur Dernière intervention   3 455
       
      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
  2. blux Messages postés 5035 Date d'inscription   Statut Modérateur Dernière intervention   3 455
     
    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
  3. WhiteFang Messages postés 2063 Statut Membre 204
     
    Hi !!
    Try "TypeName" in VB/VBA code (if applicable).... ;-)))
    Wild and Free
    0
    1. 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
  4. Pierre Fauconnier
     
    hello

    int(100000)=100000 is right, but 100000 is not an integer, but a long...
    0
    1. teebo Messages postés 33585 Date d'inscription   Statut Contributeur Dernière intervention   1 797
       
      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
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. jojo
     
    Pierre Fauconnier is rigth.
    if(int(nb)=nb && nb <257) is an integer(signed)
    :-))
    0
    1. teebo Messages postés 33585 Date d'inscription   Statut Contributeur Dernière intervention   1 797
       
      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