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
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
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
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:
>>>