Re: simple string format question

2012-10-25 Thread Neil Cerutti
On 2012-10-25, Piet van Oostrum wrote: > Adrien writes: > >> print "{:.3g}".format(2.356) # this rounds up > > But: > print "{:.3g}".format(12.356) > 12.4 print "{:.3g}".format(123.356) > 123 The precision is a decimal number indicating how many digits should be displayed after

Re: simple string format question

2012-10-24 Thread Piet van Oostrum
Adrien 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 WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list

Re: simple string format question

2012-10-15 Thread Dave Angel
On 10/15/2012 08:29 AM, Chris Rebert wrote: > On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker wrote: >> Is there a way to specify to format I want a floating point written with no >> more >> than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all >> floats written with 2 digits, e

Re: simple string format question

2012-10-15 Thread Adrien
Le 15/10/2012 14:12, Neal Becker a écrit : Is there a way to specify to format I want a floating point written with no more than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all floats written with 2 digits, even if they are 0: 2.35 << yes, that's what I want 2.00 << no, I w

Re: simple string format question

2012-10-15 Thread Kamlesh Mutha
There doesn't seem to be any direct way to achieve this. Maybe you can do something like this: import math x = 3.05 if math.modf(x)[0] != 0.0: print x Cheers, -Kamlesh On Mon, Oct 15, 2012 at 5:59 PM, Chris Rebert wrote: > On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker wrote: > > Is ther

Re: simple string format question

2012-10-15 Thread Chris Rebert
On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker wrote: > Is there a way to specify to format I want a floating point written with no > more > than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all > floats written with 2 digits, even if they are 0: > > 2.35 << yes, that's what I

simple string format question

2012-10-15 Thread Neal Becker
Is there a way to specify to format I want a floating point written with no more than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all floats written with 2 digits, even if they are 0: 2.35 << yes, that's what I want 2.00 << no, I want just 2 or 2. -- http://mail.python.o