Re: String Formatting Operations for decimals.

2010-04-01 Thread Maxim Lacrima
Hello, Chris! Thanks for your really quick reply! It works! On 1 April 2010 12:14, Chris Rebert wrote: > On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > > Hello! > > > > I need to format a decimal (floating point) number in the following > > way: > > 10 results in '10' > > 10.5 results in '1

Re: String Formatting Operations for decimals.

2010-04-01 Thread Xavier Ho
Hi Maxim, If it's the trailing zeroes you're concerned about, here's a work-around: >>> ('%.2f' % 10.5678).rstrip('0') '10.57 I'm sure there are better solutions. But this one works for your need, right? Cheers,' Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335

Re: String Formatting Operations for decimals.

2010-04-01 Thread Chris Rebert
On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > Hello! > > I need to format a decimal (floating point) number in the following > way: > 10 results in '10' > 10.5 results in '10.5' > 10.50 results in '10.5' > 10.5678 results in 10.57 > > How can I achieve this using standard Python string formatti

String Formatting Operations for decimals.

2010-04-01 Thread Lacrima
Hello! I need to format a decimal (floating point) number in the following way: 10 results in '10' 10.5 results in '10.5' 10.50 results in '10.5' 10.5678 results in 10.57 How can I achieve this using standard Python string formatting operations? Something like '%.2f' works almost as expected: >>>