Really basic problem

Zentrader zentraders at gmail.com
Mon Oct 8 18:14:56 CEST 2007


You can use Python's decimal class if floating point arithmetic is not
exact enough

import decimal
status = decimal.Decimal( 0 )
for i in range(10):
   status += decimal.Decimal( "0.1" )
   if status == decimal.Decimal( "0.1" ):
       print status
   elif status == decimal.Decimal( "0.2" ):
       print status
   elif status == decimal.Decimal( "0.3" ):
       print status
   elif status == decimal.Decimal( "0.4" ):
       print status
   elif status == decimal.Decimal( "0.5" ):
       print status
   elif status == decimal.Decimal( "0.6" ):
       print status
   elif status == decimal.Decimal( "0.7" ):
       print status
   elif status == decimal.Decimal( "0.8" ):
       print status
   elif status == decimal.Decimal( "0.9" ):
       print status
   elif status == decimal.Decimal( "1.0" ):
       print status
   else:
       print "status not equal -->", status




More information about the Python-list mailing list