newb: Python Floating Point

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnny

    #1

    newb: Python Floating Point

    When I do the following, rounding to 2 decimal places doesn't seem to
    work. I should get 0.99 :
    >>a =0.99
    >>a
    0.9899999999999 9999
    >>round(a,2)
    0.9899999999999 9999
    >>>
    thank you.

  • Robert Kern

    #2
    Re: newb: Python Floating Point

    johnny wrote:
    When I do the following, rounding to 2 decimal places doesn't seem to
    work. I should get 0.99 :
    >
    >>>a =0.99
    >>>a
    0.9899999999999 9999
    >>>round(a,2)
    0.9899999999999 9999


    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco

    Comment

    • Dan Bishop

      #3
      Re: newb: Python Floating Point

      On Mar 15, 6:09 pm, "johnny" <rampet...@gmai l.comwrote:
      When I do the following, rounding to 2 decimal places doesn't seem to
      work. I should get 0.99 :
      In binary, 0.99 is the recurring fraction 0.11 111101011100001 01000
      111101011100001 01000 111101011100001 01000 .... Thus, it can't be
      exactly represented as a float.

      Comment

      Working...