PEP 327: Decimal Data Type

Aahz aahz at pythoncraft.com
Tue Feb 10 22:09:03 EST 2004


In article <ad052e5c.0402061738.bdddcaa at posting.google.com>,
Dan Bishop <danb_83 at yahoo.com> wrote:
>Stephen Horne <steve at ninereeds.fsnet.co.uk> wrote in message news:<qeq520pv7kbd1s3ojmn3idetjuljhtk5md at 4ax.com>...
>> On 5 Feb 2004 09:18:12 -0500, aahz at pythoncraft.com (Aahz) wrote:
>>>In article <ad052e5c.0401310101.1c5bd5aa at posting.google.com>,
>>>Dan Bishop <danb_83 at yahoo.com> wrote:
>>>>
>>>>For money, it means that I have *exactly* $1.80.  This is because
>>>>"dollars" are just a notational convention for large numbers of cents.
>>>> I can just as accuately say that have an (integer) 180 cents, and
>>>>indeed, that's exactly the way it would be stored in my financial
>>>>institution's database.  (I know because I used to work there.)  So
>>>>all you really need here is "int".  But I do agree with the idea of
>>>>having a class to hide the decimal/integer conversion from the user.
>>>
>>>Really.  What kind of financial institution was this?  They didn't need
>>>to deal with any form of fractional pennies?
>> 
>> Does it really matter if they did? They may not deal in whole pennies,
>> but I seriously doubt that they need infinite precision - integers
>> with a predefined scaling factor (ie fixed point arithmetic) will, I
>> suspect, handle those few jobs that counting in pennies can't.
>
>And you would be right.  For example, interest rates were always
>stored in thousandths of a percent.
>
>The only problem was that some of the third-party software we used
>made this scaling completely visible to the user.  Our employees would
>occasionally forget the scaling factor, and this resulted in mistakes
>like having one of our CD's pay 445% interest instead of 4.45%.

...and that's a good argument for having a built-in type that handles
the conversions automatically.  Another issue is the different kinds of
rounding.  All in all, there are many kinds of already-solved problems
that are taken care of by using the decimal float standard.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death."  --GvR



More information about the Python-list mailing list