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 / C++ / MFC
  4. Receiving double value differently

Receiving double value differently

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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.
  • N Offline
    N Offline
    narasingubhanu
    wrote on last edited by
    #1

    I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?

    CPalliniC J 2 Replies Last reply
    0
    • N narasingubhanu

      I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      "What Every Computer Scientist Should Know About Floating-Point Arithmetic"[^].

      Veni, vidi, vici.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • N narasingubhanu

        I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        Floating point numbers used by computers can be only rational (have a limited number of digits). When storing irrational numbers, the stored value must be rounded. Numbers are also stored internally with base 2. So not all decimal numbers (base 10) can be represented as identical base 2 numbers (while the decimal number is rational, the converted base 2 number may be irrational). See the section 'Representable numbers, conversion and rounding' in the Floating point[^] Wikipedia article for a more detailed explanation.

        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