[New-bugs-announce] [issue10813] Suppress adding decimal point for places=0 in moneyfmt()

Carsten Grohmann report at bugs.python.org
Mon Jan 3 13:58:07 CET 2011

New submission from Carsten Grohmann <carstengrohmann at gmx.de>:


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.

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

--- 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 @@
     for i in range(places):
         build(next() if digits else '0')
-    build(dp)
+    if places:
+        build(dp)
     if not digits:
     i = 0

What do you think about the change?


assignee: docs at python
components: Documentation
messages: 125164
nosy: cgrohmann, docs at python
priority: normal
severity: normal
status: open
title: Suppress adding decimal point for places=0 in moneyfmt()

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list