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.

classification
Title: moneyfmt recipe in decimal documentation has error
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: annarave, rhettinger
Priority: normal Keywords:

Created on 2004-11-23 09:56 by annarave, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg23268 - (view) Author: Anna Ravenscroft (annarave) Date: 2004-11-23 09:56
In the new 2.4c1 documentation for decimal, section
5.6.7 Recipes, there is a moneyfmt function - which
mostly works pretty well.  It adds a separator between
every 3 digits. 

Unfortunately, it adds the separator even when there
are no further digits. So, for example, you can end up
with:

$,437.00

instead of 
$437.00

I propose a simple fix:
    while digits:
        append(next())
        i += 1
        if i % 3 == 0: append(sep)
    if result[-1] == sep: result.pop() # add this line

This would make the moneyfmt function much more usable. 

Anna
msg23269 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-11-24 05:53
Logged In: YES 
user_id=80475

Thanks for the timely bug report.

Adopted a simpler solution -- only adding a separator when
more digits remain:

-        if i == 3:
+        if i == 3 and digits:

Also added at test to cover this case.

See Doc/lib/libdecimal.tex 1.22
History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41212
2004-11-23 09:56:24annaravecreate