Hello, Chris!<br><br>Thanks for your really quick reply! It works!<br><br><br><div class="gmail_quote">On 1 April 2010 12:14, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Thu, Apr 1, 2010 at 2:08 AM, Lacrima <<a href="mailto:lacrima.maxim@gmail.com">lacrima.maxim@gmail.com</a>> wrote:<br>

> Hello!<br>
><br>
> I need to format a decimal (floating point) number in the following<br>
> way:<br>
> 10 results in '10'<br>
> 10.5 results in '10.5'<br>
> 10.50 results in '10.5'<br>
> 10.5678 results in 10.57<br>
><br>
> How can I achieve this using standard Python string formatting<br>
> operations?<br>
> Something like '%.2f' works almost as expected:<br>
>>>> '%.2f' % 10.5<br>
> '10.50'<br>
>>>> '%.2f' % 10.5678<br>
> '10.57'<br>
>>>> '%.2f' % 10<br>
> '10.00'<br>
> But I always need trailing zeros to be excluded, i.e. 10.5 should<br>
> result in '10.5' (not '10.50'), and 10 should result in '10' (not<br>
> '10.00').<br>
> So how can I do this?<br>
<br>
</div>('%.2f' % 10).rstrip('0').rstrip('.')<br>
<br>
Cheers,<br>
Chris<br>
<font color="#888888">--<br>
<a href="http://blog.rebertia.com" target="_blank">http://blog.rebertia.com</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>with regards,<br>Maxim<br>