default print format for floats
vincent at visualtrans.de
Mon Mar 1 20:45:49 CET 2004
"vincent wehren" <vincent at visualtrans.de> schrieb im Newsbeitrag
news:c201sl$aif$1 at news2.tilbu1.nb.home.nl...
| <beliavsky at aol.com> schrieb im Newsbeitrag
| news:3064b51d.0403011046.4238998d at posting.google.com...
| | By default, Python prints many floating point numbers with 17 digits
| | after the decimal place. I would like to make the DEFAULT 4 decimal
| | places. Is this possible?
| | For example, the code
| | from string import join
| | x = [1.0,0.3,0.4]
| | print x
| | print join(["%4.1f" % y for y in x])
| | gives the output
| | [1.0, 0.29999999999999999, 0.40000000000000002]
| | 1.0 0.3 0.4
| | I want the simplicity of "print x", without so many decimal places.
| I wouldn't cjanging "DEFAULT BEHAVIOR", but a slight modification of the
This was supposed to read "I wouldn't call it changing "DEFAULT BEHAVIOR"...
Don't know what my fingers where thinking ;)
| gives you:
| >>> x = [1.0, 0.3, 0.4]
| >>> print ", ".join(["%.4f" % y for y in x])
| 1.0000, 0.3000, 0.4000
| Is this what you're after?
| Vincent Wehren
More information about the Python-list