diff options
author | Raymond Hettinger <python@rcn.com> | 2008-02-14 12:49:37 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-02-14 12:49:37 (GMT) |
commit | 0cd717007dad8dc29f0dc27b369f8ceac28d904c (patch) | |
tree | ed82d37447f2014d78516b77126bdf59adbfc668 /Doc/library | |
parent | 3b718a79af900fdacaf0b825137f69eadc753765 (diff) | |
download | cpython-0cd717007dad8dc29f0dc27b369f8ceac28d904c.zip cpython-0cd717007dad8dc29f0dc27b369f8ceac28d904c.tar.gz cpython-0cd717007dad8dc29f0dc27b369f8ceac28d904c.tar.bz2 |
Simplify moneyfmt() recipe.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/decimal.rst | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 75db486..18ade40 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -1404,19 +1404,15 @@ to work with the :class:`Decimal` class:: '<.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 @@ to work with the :class:`Decimal` class:: 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. |