summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-08-04 20:56:28 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-08-04 20:56:28 (GMT)
commit388122d43b2b6bb41774d9680b9ad3bc05682f85 (patch)
tree4b3059b3dbd916fde44702e732f507788c433fbf /Doc
parentb6c50749207688902a6378958da474f7c31f179d (diff)
downloadcpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.zip
cpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.tar.gz
cpython-388122d43b2b6bb41774d9680b9ad3bc05682f85.tar.bz2
Issue #9337: Make float.__str__ identical to float.__repr__.
(And similarly for complex numbers.)
Diffstat (limited to 'Doc')
-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.