strings (dollar.cents) into floats

Steve Holden steve at holdenweb.com
Fri Aug 31 16:59:51 CEST 2007


Ben Finney wrote:
> Wildemar Wildenburger <lasses_weil at klapptsowieso.net> writes:
> 
>> But what use is there for floats, then? When is it OK to use them?
> 
> When one is willing to sacrifice decimal precision for speed of
> calculation, and doesn't need the numbers to stay precise. E.g. when
> performing millions of calculations on real-world (analogue)
> measurements.
> 
Traditionally, mainframe computers used BCD arithmetic to handle 
currency, and the Decimal module is probably the best way to proceed if 
your Python is recent enough to include it.

That isn't to say that currencies can't be handled using floating-point. 
The important thing then becomes to round after each calculation rather 
than allowing the errors to build up until they become significant 
enough to make a difference to the final result.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list