proposed language change to int/int==float (was: PEP0238 lament)

Guido van Rossum guido at python.org
Fri Jul 27 22:52:26 EDT 2001


Lloyd Zusman <ljz at asfast.com> writes:

> Lately I've been consulting on Wall Street, and it turns out that in
> the computations done in that universe, there is a great need for
> non-float decimal types, such as your example about 0.98 being used as
> a price.
> 
> Accountants and their kin want ledgers, positions, etc. to balance to
> the penny (or centavo, or whatever is the smallest fractional currency
> in a given country).  This can only be accomplished using decimal
> arithmetic ... like Bignums with implied decimal places.

I think there are two variations here.  You can use binary BinNums
with an implied decimal point, e.g. the tuple <314, 2> might represent
3.14 and <4, 0> might represent 4.  Or you can actually use decimal or
packed decimal as the storage format.  The latter is probably a bit
slower than binary and slightly less storage-efficient, but has a huge
advantage for I/O conversion (no need to divide to print the number).
If you don't do a lot of computation but you do a lot of I/O that can
be a huge advantage.

If all you need is to make sure your pennies add up, binary is fine.
If your app is I/O intensive, decimal may be better.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list