How to check if a number is integer or not

i want to know to check in a program if the user has entered an enteger number or not

5 réponses

  • Votes
  • Date
  • Date décroissante
  1. Contributeur sécurité
    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. Modérateur
      yes, you're right...
      sorry, I was tired...

      A+ Blux            "Les cons, ça ose tout.
      C'est même à ça qu'on les reconnait"
  2. Modérateur
    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"
    1. Hi !!
      Try "TypeName" in VB/VBA code (if applicable).... ;-)))
      Wild and Free
      1. 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 ;-)))
    2. hello

      int(100000)=100000 is right, but 100000 is not an integer, but a long...
      1. Contributeur
        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"
    3. Pierre Fauconnier is rigth.
      if(int(nb)=nb && nb <257) is an integer(signed)
      :-))
      1. Contributeur
        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"