PEP 327: Decimal Data Type

Stephen Horne steve at ninereeds.fsnet.co.uk
Thu Feb 5 21:49:26 EST 2004


On 5 Feb 2004 09:16:51 -0500, aahz at pythoncraft.com (Aahz) wrote:

>In article <6ltk10h30riel0lghd18t5unjco2g26spi at 4ax.com>,
>Stephen Horne  <steve at ninereeds.fsnet.co.uk> wrote:
>>On Fri, 30 Jan 2004 09:49:05 -0300, "Batista, Facundo"
>><FBatista at uniFON.com.ar> wrote:
>>>
>>>I'll apreciate any feedback. Thank you all in advance.
>>
>>My concern is that many people will use a decimal type just because it
>>is there, without any consideration of whether they actually need it.
>>
>>95% of the time or more, all you need to do to represent money is to
>>use an integer and select appropriate units (pence rather than pounds,
>>cents rather than dollars, etc) so that the decimal point is just a
>>presentation issue when the value is printed/displayed but is never
>>needed in the internal representation.
>
>The problem lies precisely in that representation.  For starters, a
>binary integer is O(n^2) for conversion to decimal printing.

In practice, there is an upper limit to the size of number that occurs
in any financial use, and of course we are not talking about tens of
digits let alone hundreds, meaning that the conversion is most
sensibly treated as O(1) for each number converted.

Anyway, speeding up the presentation of results makes little sense if
you slow down all the arithmetic operations to do it.

>  Then
>there's the question about multi-currency conversions, or interest
>rates, or ....

Admittedly needing better than penny precision, but still fixed
precision (ie suiting an integer representation with an implicit scale
factor) and the results are rounded.

I work with a company that writes accounting software. We don't need
to worry about currency conversions, but we do need to worry about
interest and other cases where fractional pennies seem to be implied
(rates for taxes, allowances etc) and basically the fractional pennies
are never really an issue - you do have to be careful with the
rounding rules, but that applies whatever representation you use.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list