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. Visual Basic
  4. I was thinking that the result of 50\1000 was 0.05 ........

I was thinking that the result of 50\1000 was 0.05 ........

Scheduled Pinned Locked Moved Visual Basic
helpcsharpquestion
6 Posts 4 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.
  • H Offline
    H Offline
    Hurricane3000
    wrote on last edited by
    #1

    Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.

    modified on Sunday, January 17, 2010 12:32 PM

    D D 2 Replies Last reply
    0
    • H Hurricane3000

      Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.

      modified on Sunday, January 17, 2010 12:32 PM

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Single is a single precision float (from MSDN). I think this should explain. You can use decimal and I think it would give correct result.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      H 1 Reply Last reply
      0
      • D dan sh

        Single is a single precision float (from MSDN). I think this should explain. You can use decimal and I think it would give correct result.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        H Offline
        H Offline
        Hurricane3000
        wrote on last edited by
        #3

        Hi D@nish, Single is a single precision float, but normally it returns decimal numbers. I tryed to use Decimal type (return 0D value), but the problem is not resolved yet. Here seems that the result is strangely cutted after the first decimal number.....

        1 Reply Last reply
        0
        • H Hurricane3000

          Hi all, I have a strange problem: Dim X As Single = 50 Dim Y As Single = 1000 Dim Z As Single = X \ Y Why Z return me 0.0 as result of operation instead that 0.05? If X is 100, then the result is correct (0.1). I also tried to dimensione variables as Double, and to use Double.Parse instruction, but without resolve the problem. All this is in a VB .Net Compact Framework routine. Surely the problem is a "false" problem, but now I have a momentary "mind vacuum"..... Thanks for help.

          modified on Sunday, January 17, 2010 12:32 PM

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

          You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          H D 2 Replies Last reply
          0
          • D Dave Kreskowiak

            You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            H Offline
            H Offline
            Hurricane3000
            wrote on last edited by
            #5

            Thanks Dave, Without your help I risked to spend one week to try to resolve a false problem, and with no warranty to solve it in one week!

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              You're using the wrong slash. The Forward Slash, /, will give the correct result. The Backslash, \, does integer division.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              D Offline
              D Offline
              Dalek Dave
              wrote on last edited by
              #6

              GENIUS I couldn't work out why it wasn't happening! Although you could have been a bit of a smartarse over that, it was nice to see you just pointed out what others failed to see!

              ------------------------------------ No Good Deed Goes Unpunished Clare Boothe Luce

              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