Numeric data question

terry tg5027 at citlink.net
Wed Jul 24 12:32:04 EDT 2002


>>  Well, PostgreSQL does have a money type, but IIRC it's just a
>> float with a fixed number of decimal places. You could just
>> use pennies as the unit and integer math though.

Thanks Tim, it is a more complex representation than just float 
as it also contains the decimal places.  I haven't seen the exact 
internal format in Postgres, but it's a very common datatype in 
many databases.  In general it's not appropriate/legal to use 
integer or floating point math when dealing with money.  It 
creates too many coding dependent variations in results - not to 
mention maintenance nightmares.

I'm guessing now (from lack of real experience) that being a 
'typeless' language that I would be forced into contriving a 
method for handling money such that I could never code something 
straightforwardly like:  
TotalCost = Quantity * UnitCost
 (where Quantity is integer and the others money).

Am I loonie, or is Python just not inherently suitable for 
accounting applications for this reason?

terry 




More information about the Python-list mailing list