[ python-Bugs-1778207 ] rounding inconsisntency using string formatting
SourceForge.net
noreply at sourceforge.net
Tue Aug 21 01:20:21 CEST 2007
Bugs item #1778207, was opened at 2007-08-20 16:20
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1778207&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jim Hurlburt (jim_hurlburt)
Assigned to: Nobody/Anonymous (nobody)
Summary: rounding inconsisntency using string formatting
Initial Comment:
Sirs:
Using python to generate a text file for transfer of data between systems, I seem to be getting inconsistent rounding results using a text formatting string
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
print "%9.4f" % (229.0 * .325,) -> 74.4250 correct
print "%9.2f" % (round(74.425, 2),) -> 74.43 correct
print "%9.2f" % (74.425,) -> 74.42 wrong
print "%9.2f" % (167.255,) -> 167.26 correct
print "%9.2f" % (167.2551,) -> 167.26 correct
print "%9.2f" % (167.2549,) -> 167.25 correct
It appears as if the string formatting code is a bit flakey. Perhaps working in binary with too small a precision?
For a bit I thought it might be "Round even up, odd down at the .005 break, but that doesn't appear to be the case.
Now that I know it's there, I can do a workaround.
Seems as if it deserves a fix or at least a document notation of the problem.
Thanks in advance,
Jim Hurlburt
Atrium Windows and Doors
Yakima, WA
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1778207&group_id=5470
More information about the Python-bugs-list
mailing list