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. Numeric Calc Proplem

Numeric Calc Proplem

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 2 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    All, 1) Why does Dim mResult as double mResult = 0.1 * 0.1 return mResult = 0.010000000000000002? What can I do about it? Thanks, Joe

    D 1 Reply Last reply
    0
    • A Anonymous

      All, 1) Why does Dim mResult as double mResult = 0.1 * 0.1 return mResult = 0.010000000000000002? What can I do about it? Thanks, Joe

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      You cannot trust double nor float results on any language (to be picky, those who use IEEE floating point arithmetic): they are subject to rounding errors. A full description of the causes can be found on several articles on the web, like here Search google for, e.g., IEEE rounding errors. There are quick ways of working this around: 1. round the results 2. don't compare with '=', use a 'between'-like comparison. 3. Use the Decimal data type. Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier

      A 1 Reply Last reply
      0
      • D Daniel Turini

        You cannot trust double nor float results on any language (to be picky, those who use IEEE floating point arithmetic): they are subject to rounding errors. A full description of the causes can be found on several articles on the web, like here Search google for, e.g., IEEE rounding errors. There are quick ways of working this around: 1. round the results 2. don't compare with '=', use a 'between'-like comparison. 3. Use the Decimal data type. Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Rounding worked great - thanks. I'll read those references to get educated - I haven't done very much numeric computing stuff.

        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