how to convert from Decimal('1.23456789') to Decimal('1.234')

Hyunchul Kim sundol at sfc.keio.ac.jp
Mon Mar 23 03:21:27 EDT 2009


In that case, I usually use

# when rounding is proper,
s = '1.23456789'
print round(float(s))

or

# when cut out is proper,
from math import floor
print floor(float(s)*1000)/1000

Hyunchul

valpa wrote:
> I only need the 3 digits after '.'
>
> Is there any way other than converting from/to string?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>   




More information about the Python-list mailing list