Announcement

Collapse
No announcement yet.

cplusplus Q

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • cplusplus Q

    Does anyone know if there is a function to check whether a float/double is actually an integer in Visual C++.

    In borland C++ there is something like IsInt(), but I can't find a Visual C++ equivalent.
    ☕ 🍔 🍅 🍊🍏

  • #2
    Tech Support

    Comment


    • #3
      Nailed: can you take this thread across a few more forums so it can get more readers?
      ☕ 🍔 🍅 🍊🍏

      Comment


      • #4
        you'll generally find that the people who know about this stuff and actually want to help will check this forum

        Comment


        • #5
          Not sure about Visual C++, but to test if "x" is an integer, you could always do:

          if ((x - (int)x) == 0.0) ...

          Comment


          • #6
            Yeah, that'll work.

            Comment


            • #7
              ?go google
              FREE MANDELA

              Comment


              • #8
                Originally posted by Vertigo5
                Not sure about Visual C++, but to test if "x" is an integer, you could always do:

                if ((x - (int)x) == 0.0) ...
                That's how I did it, but I wanted to look more professional. :fear:
                ☕ 🍔 🍅 🍊🍏

                Comment


                • #9
                  For now use a #define

                  Comment


                  • #10
                    Originally posted by Stultus
                    ?go google
                    Made me laugh
                    :whistling

                    Comment


                    • #11
                      More professional? Then do this:

                      if isInt(x)
                      ...




                      private Boolean isInt(double x)
                      {

                      if ((x - (int)x) == 0.0)
                      return true;
                      else
                      return false;
                      }
                      Last edited by MetalKid; 04-25-2005, 03:36 PM.

                      Comment


                      • #12
                        Or just:

                        private inline bool isInt(double x) {
                        return (x - int(x)) == 0.0;
                        }

                        The if is not required.
                        Zemyla>You know, quoting yourself in your sig is a sign of irredeemable narcissism.

                        GuruMeditation> You're on SS, you're an it.
                        GuruMeditation> Unless your ship grows boobs, in that case you're a freak.

                        Originally posted by sexy wooden spoon
                        Also u cud tlk about helping language skills.

                        Comment


                        • #13
                          bool isInt(float f)
                          {
                          return (float)(int)f == f;
                          }

                          Comment

                          Working...
                          X