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 cgrohmann
Recipients cgrohmann, docs@python
Date 2011-01-03.12:58:01
SpamBayes Score 0.0013382871
Marked as misclassified No
Message-id <1294059487.44.0.656415691247.issue10813@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

the documentation of the decimal module contains a small recipe called moneyfmt() for format decimal values. It's very usefull.

I'd like to suggest a small improvement because the output is incorrect with given dp="." (default) and places=0.

Example:
>>> moneyfmt(decimal.Decimal('-0.02'), neg='<', trailneg='>', places=1)
'<0.0>'
>>> moneyfmt(decimal.Decimal('-0.02'), neg='<', trailneg='>', places=0)
'<0.>'

Change:
--- moneyfmt.py 2011-01-03 13:56:32.774169788 +0100
+++ moneyfmt.py.new     2011-01-03 13:56:58.130165330 +0100
@@ -33,7 +33,8 @@
         build(trailneg)
     for i in range(places):
         build(next() if digits else '0')
-    build(dp)
+    if places:
+        build(dp)
     if not digits:
         build('0')
     i = 0

What do you think about the change?

Regrads,
Carsten
History
Date User Action Args
2011-01-03 12:58:07cgrohmannsetrecipients: + cgrohmann, docs@python
2011-01-03 12:58:07cgrohmannsetmessageid: <1294059487.44.0.656415691247.issue10813@psf.upfronthosting.co.za>
2011-01-03 12:58:02cgrohmannlinkissue10813 messages
2011-01-03 12:58:01cgrohmanncreate