Marc Christiansen wrote:
> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:
>>
>>> On 6 12 , 3 16 , ici <[EMAIL PROTECTED]> wrote:
>>>> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>>>>
>>>> > How could I format the float number like this: (keep 2 digit
>>>> > precision)
>>>> > 1.002 => 1
>>>> > 1.12 => 1.12
>>>> >>> print "%.02f" % (2324.012)
>>>> 2324.01
> Or:
>
> def my_other_formatter_ommitting_trailing_zeroes(value):
> result = '%.2f' % value
> return result.rstrip('0.')
Make that result.rstrip("0").rstrip("."), or it may fail:
>>> ("%.2f" % 100.0).rstrip(".0")
'1' # wrong
>>> ("%.2f" % 100.0).rstrip("0").rstrip(".")
'100'
Peter
--
http://mail.python.org/mailman/listinfo/python-list