decimal and trunkating

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Thu Jun 2 15:20:19 CEST 2005


F. Petitjean wrote:
> Le Thu, 02 Jun 2005 19:59:08 +1000, Timothy Smith a écrit :
>> i want to trunkate 199.999 to 199.99
> 
> round(199.999, 2)  # 2 digits after the decimal point

Wrong. This will yield 200.00.

>> do i really have to use floats to do this?
> 
> 19.999  is a float : 
> type(19.999) is float  #  ==> True

He is speaking of Decimals...

d = Decimal("199.999")
d._round(5, decimal.ROUND_DOWN)

Reinhold



More information about the Python-list mailing list