Skip to content

round() does not #45900

Closed
Closed

Description

@travelgirl
mannequin
BPO 1559
Nosy @gvanrossum, @birkenfeld
Files
  • python bug.jpg
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-12-05.20:31:01.007>
    created_at = <Date 2007-12-05.19:58:11.540>
    labels = ['type-bug', 'invalid', 'OS-windows']
    title = 'round() does not'
    updated_at = <Date 2007-12-06.00:40:39.176>
    user = 'https://bugs.python.org/travelgirl'

    bugs.python.org fields:

    activity = <Date 2007-12-06.00:40:39.176>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-12-05.20:31:01.007>
    closer = 'georg.brandl'
    components = ['Windows']
    creation = <Date 2007-12-05.19:58:11.540>
    creator = 'travelgirl'
    dependencies = []
    files = ['8882']
    hgrepos = []
    issue_num = 1559
    keywords = []
    message_count = 5.0
    messages = ['58225', '58227', '58230', '58231', '58235']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'georg.brandl', 'travelgirl']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1559'
    versions = ['Python 2.5']

    Activity

    1. travelgirl commented on Dec 5, 2007

      travelgirlmannequin
      MannequinAuthor

      http://docs.python.org/tut/node5.html states, as an example, round(, 2)
      should round to the second decimal place. makes sense. when i
      attempted it with different numbers, round() returned what looks like a
      binary-coded decimal error (see the jpg enclosed), and did not return
      just two digits, but 15 digits. the same error was produced for
      round(
      , 3). when the number was changed to 1 digit, the return result
      rounded from another direction.

      i'd guess this isn't a feature :)

    2. added
      type-bug
      on Dec 5, 2007
    3. birkenfeld commented on Dec 5, 2007

      @birkenfeld
      Member

      Not really a feature, but not a bug. See
      http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
      for an explanation.

    4. travelgirl commented on Dec 5, 2007

      travelgirlmannequin
      MannequinAuthor

      interesting, and expected as the BCD calculation. however, the round function should be able to handle that correctly, dealing with the number in a string fashion as opposed a mathematical one, to display the requested decimal places. slower, to be sure, but hella accurate.

      that's what the bug was about. i understand the issues with BCD. i don't understand how a function to display a number can get the display so wrong, even when the BCD number itself "fails" to the 15th place. round to 2 places, you should still display 14.78, not 14.7799999999999999x

      just my take. thanks for getting back to me.

      00 caren
      http://www.parkgallery.org
      george davis creek, north fork

    5. birkenfeld commented on Dec 5, 2007

      @birkenfeld
      Member

      round() does not return a string, but a floating point number, the best
      approximation to the "real" result that is achievable with the limited
      precision of binary floating point.

      That result is then formatted to a string for display by the interactive
      interpreter using the repr() function, which formats a float with (I
      think) 17 decimal digits.

      So, the point here is that repr() produces "too many" digits for your
      liking ;) You can use str() to cut off at fewer digits, which will
      produce the "correct" string in most cases.

    6. gvanrossum commented on Dec 6, 2007

      @gvanrossum
      Member

      travelgirl: the 'decimal' module is designed to deal with this. Note
      that there's a difference between BCD (which can represent decimal
      numbers exactly) and binary (which can't, in general).

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      OS-windowstype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions