simple string format question

Piet van Oostrum piet at vanoostrum.org
Wed Oct 24 23:48:02 EDT 2012


Adrien <adnothing at gmail.com> writes:

> print "{:.3g}".format(2.356)  # this rounds up

But:

>>> print "{:.3g}".format(12.356) 
12.4
>>> print "{:.3g}".format(123.356) 
123

-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list