Hi Maxim,<br><br>If it's the trailing zeroes you're concerned about, here's a work-around: <br><br>>>> ('%.2f' % 10.5678).rstrip('0')<br>'10.57<br><br>I'm sure there are better solutions. But this one works for your need, right?<br>
<br>Cheers,'<br><br clear="all">Ching-Yun Xavier Ho, Technical Artist<br><br>Contact Information<br>Mobile: (+61) 04 3335 4748<br>Skype ID: SpaXe85<br>Email: <a href="mailto:contact@xavierho.com">contact@xavierho.com</a><br>
Website: <a href="http://xavierho.com/">http://xavierho.com/</a><br>
<br><br><div class="gmail_quote">On Thu, Apr 1, 2010 at 7:08 PM, Lacrima <span dir="ltr"><<a href="mailto:lacrima.maxim@gmail.com">lacrima.maxim@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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>
Sorry for my English.<br>
Thanks in advance.<br>
<br>
with regards,<br>
Maxim<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>