Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Division result is always zero?

Division result is always zero?

Scheduled Pinned Locked Moved C#
question
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Star09
    wrote on last edited by
    #1

    MessageBox.Show(Convert.ToString(1/7)); The result is always zero, when it should have been 0.1428571429 Any ideas? --Star

    G D 2 Replies Last reply
    0
    • S Star09

      MessageBox.Show(Convert.ToString(1/7)); The result is always zero, when it should have been 0.1428571429 Any ideas? --Star

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Cast

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      S 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        Cast

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        S Offline
        S Offline
        Star09
        wrote on last edited by
        #3

        Still result is zero.

        G 1 Reply Last reply
        0
        • S Star09

          Still result is zero.

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          It means that you should cast other things :)

          Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

          S 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            It means that you should cast other things :)

            Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

            S Offline
            S Offline
            Star09
            wrote on last edited by
            #5

            I don't get it? :doh: Can you please explain? too much coffee and a lot less sleep :(( --Star

            F 1 Reply Last reply
            0
            • S Star09

              I don't get it? :doh: Can you please explain? too much coffee and a lot less sleep :(( --Star

              F Offline
              F Offline
              fly904
              wrote on last edited by
              #6

              MessageBox.Show(Convert.ToString((double)1/7));

              My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

              S 1 Reply Last reply
              0
              • F fly904

                MessageBox.Show(Convert.ToString((double)1/7));

                My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

                S Offline
                S Offline
                Star09
                wrote on last edited by
                #7

                Thank you!!!!:thumbsup: (double)(1/7) I keep adding the parentheses, something so simple could make you go crazy...but I guess that's coding for you..lol Thanks again

                H 1 Reply Last reply
                0
                • S Star09

                  Thank you!!!!:thumbsup: (double)(1/7) I keep adding the parentheses, something so simple could make you go crazy...but I guess that's coding for you..lol Thanks again

                  H Offline
                  H Offline
                  Henry Minute
                  wrote on last edited by
                  #8

                  You could also do MessageBox.Show(Convert.ToString(1.00/7.00));

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                  1 Reply Last reply
                  0
                  • S Star09

                    MessageBox.Show(Convert.ToString(1/7)); The result is always zero, when it should have been 0.1428571429 Any ideas? --Star

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    What you wrote was, in vague pseudo-code, Convert.ToString( (Integer 1) / (Integer 7) ). In integer math, the only possible answer is a while number. Since the result, 0.1428, would be truncated to the whole number, 0 is what you got.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups