summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial/floatingpoint.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tutorial/floatingpoint.rst')
-rw-r--r--Doc/tutorial/floatingpoint.rst11
1 files changed, 5 insertions, 6 deletions
diff --git a/Doc/tutorial/floatingpoint.rst b/Doc/tutorial/floatingpoint.rst
index c06568e..863fb28 100644
--- a/Doc/tutorial/floatingpoint.rst
+++ b/Doc/tutorial/floatingpoint.rst
@@ -92,18 +92,17 @@ thing in all languages that support your hardware's floating-point arithmetic
(although some languages may not *display* the difference by default, or in all
output modes).
-Python's built-in :func:`str` function produces only 12 significant digits, and
-you may wish to use that instead. It's unusual for ``eval(str(x))`` to
-reproduce *x*, but the output may be more pleasant to look at::
+For more pleasant output, you may may wish to use string formatting to produce a limited number of significant digits::
- >>> str(math.pi)
+ >>> format(math.pi, '.12g') # give 12 significant digits
'3.14159265359'
+ >>> format(math.pi, '.2f') # give 2 digits after the point
+ '3.14'
+
>>> repr(math.pi)
'3.141592653589793'
- >>> format(math.pi, '.2f')
- '3.14'
It's important to realize that this is, in a real sense, an illusion: you're
simply rounding the *display* of the true machine value.