diff Doc/tutorial/stdlib2.rst @ 57428:337ebb829b8c legacy-trunk

Fix some documentation examples involving the repr of a float.
author Mark Dickinson <dickinsm@gmail.com>
date Tue, 24 Nov 2009 14:27:02 +0000
parents e05322efca85
children f7f5e1d27e06
line wrap: on
line diff
--- a/Doc/tutorial/stdlib2.rst	Tue Nov 24 14:17:29 2009 +0000
+++ b/Doc/tutorial/stdlib2.rst	Tue Nov 24 14:27:02 2009 +0000
@@ -362,10 +362,13 @@
 becomes significant if the results are rounded to the nearest cent::
 
    >>> from decimal import *
-   >>> Decimal('0.70') * Decimal('1.05')
+   >>> x = Decimal('0.70') * Decimal('1.05')
+   >>> x
    Decimal('0.7350')
-   >>> .70 * 1.05
-   0.73499999999999999
+   >>> x.quantize(Decimal('0.01'))  # round to nearest cent
+   Decimal('0.74')
+   >>> round(.70 * 1.05, 2)         # same calculation with floats
+   0.73
 
 The :class:`Decimal` result keeps a trailing zero, automatically inferring four
 place significance from multiplicands with two place significance.  Decimal