This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jim_hurlburt
Recipients
Date 2007-08-20.23:20:21
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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
History
Date User Action Args
2007-08-23 14:59:22adminlinkissue1778207 messages
2007-08-23 14:59:22admincreate