summaryrefslogtreecommitdiffstats
path: root/Doc/library/decimal.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-22 10:56:23 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-22 10:56:23 (GMT)
commit17baef0b7c7986619b7db46c70239f6b1a7d6a8f (patch)
treebae7021097e9d7f3c3fad8f1264097328d599cf4 /Doc/library/decimal.rst
parent86f38c81ae2ff13c12dacd4137916e041e42da46 (diff)
downloadcpython-17baef0b7c7986619b7db46c70239f6b1a7d6a8f.zip
cpython-17baef0b7c7986619b7db46c70239f6b1a7d6a8f.tar.gz
cpython-17baef0b7c7986619b7db46c70239f6b1a7d6a8f.tar.bz2
Activate the Sphinx doctest extension and convert howto/functional to use it.
Diffstat (limited to 'Doc/library/decimal.rst')
-rw-r--r--Doc/library/decimal.rst17
1 files changed, 12 insertions, 5 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 2d2ae93..cbd3950 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -15,9 +15,12 @@
.. sectionauthor:: Raymond D. Hettinger <python at rcn.com>
-
.. versionadded:: 2.4
+.. testsetup:: *
+
+ from decimal import *
+
The :mod:`decimal` module provides support for decimal floating point
arithmetic. It offers several advantages over the :class:`float` datatype:
@@ -47,7 +50,7 @@ arithmetic. It offers several advantages over the :class:`float` datatype:
* Unlike hardware based binary floating point, the decimal module has a user
alterable precision (defaulting to 28 places) which can be as large as needed for
- a given problem::
+ a given problem:
>>> getcontext().prec = 6
>>> Decimal(1) / Decimal(7)
@@ -115,7 +118,9 @@ Quick-start Tutorial
The usual start to using decimals is importing the module, viewing the current
context with :func:`getcontext` and, if necessary, setting new values for
-precision, rounding, or enabled traps::
+precision, rounding, or enabled traps:
+
+.. doctest:: newcontext
>>> from decimal import *
>>> getcontext()
@@ -130,7 +135,7 @@ create a Decimal from a :class:`float`, first convert it to a string. This
serves as an explicit reminder of the details of the conversion (including
representation error). Decimal numbers include special values such as
:const:`NaN` which stands for "Not a number", positive and negative
-:const:`Infinity`, and :const:`-0`. ::
+:const:`Infinity`, and :const:`-0`.
>>> Decimal(10)
Decimal('10')
@@ -149,7 +154,9 @@ representation error). Decimal numbers include special values such as
The significance of a new Decimal is determined solely by the number of digits
input. Context precision and rounding only come into play during arithmetic
-operations. ::
+operations.
+
+.. doctest:: newcontext
>>> getcontext().prec = 6
>>> Decimal('3.0')