[Python-checkins] r60798 - python/trunk/Doc/library/decimal.rst

raymond.hettinger python-checkins at python.org
Thu Feb 14 13:49:37 CET 2008


Author: raymond.hettinger
Date: Thu Feb 14 13:49:37 2008
New Revision: 60798

Modified:
   python/trunk/Doc/library/decimal.rst
Log:
Simplify moneyfmt() recipe.

Modified: python/trunk/Doc/library/decimal.rst
==============================================================================
--- python/trunk/Doc/library/decimal.rst	(original)
+++ python/trunk/Doc/library/decimal.rst	Thu Feb 14 13:49:37 2008
@@ -1404,19 +1404,15 @@
        '<.02>'
 
        """
-       q = Decimal((0, (1,), -places))    # 2 places --> '0.01'
-       sign, digits, exp = value.quantize(q).as_tuple()
-       assert exp == -places    
+       q = Decimal(10) ** -places      # 2 places --> '0.01'
+       sign, digits, exp = value.quantize(q).as_tuple()  
        result = []
        digits = map(str, digits)
        build, next = result.append, digits.pop
        if sign:
            build(trailneg)
        for i in range(places):
-           if digits:
-               build(next())
-           else:
-               build('0')
+           build(next() if digits else '0')
        build(dp)
        i = 0
        while digits:
@@ -1426,12 +1422,8 @@
                i = 0
                build(sep)
        build(curr)
-       if sign:
-           build(neg)
-       else:
-           build(pos)
-       result.reverse()
-       return ''.join(result)
+       build(neg if sign else pos)
+       return ''.join(reversed(result))
 
    def pi():
        """Compute Pi to the current precision.


More information about the Python-checkins mailing list