Decimal arithmatic, was Re: Python GUI app to impress the bos s?

sismex01 at sismex01 at
Wed Sep 25 10:00:48 EDT 2002

> > 
> > There ought to be severe penalties for idiots that use 
> > floating point dollars for financial applications.
> > If forced to use floating point (e.g. because customer
> > demands BASIC), then keep money amounts in whole pennies
> > (or whatever the smallest currency unit for the country
> > is), and divide by 100 (or whatever) for printing only (or 
> > just add the decimal point yourself).
> > 
> In many circumstances this is exactly what you can't do.
> The minute you need to calculate percentages you will get in to
> the things like .0001254 of a cent, no matter what is you
> smallest unit of currency.
> I worked for a insurance company (using Business Basic) many
> years ago on MAI and Prime gear, and we did everything as floats
> with 14 places after the decimal point,and only rounded when
> a human needed to see a number, and then used standard accounting
> practices for rounding,
> Rgds
> Tim

OK, so don't use whole pennies (or smallest currency) as your
base, use 10,000ths of a penny, but still use integer arithmetic
for your calculations.

Floating point has too many rounding errors to be trustworthy;
or, looking at it from another angle, floating-point calculations
cannot be 100% accurate because of the way it's implemented.


La informacion contenida en este mensaje es confidencial y restringida y
esta destinada unicamente para el uso de la persona arriba indicada, Esta
comunicacion representa la opinion personal del remitente y no refleja
necesariamente la opinion de la Compañia. Se le notifica que esta
estrictamente prohibida cualquier difusion, distribucion o copia de este
mensaje. Si ha recibido esta comunicacion o copia de este mensaje por error,
o si hay problemas en la transmision, favor de comunicarse con el remitente.

Todo el correo electrónico enviado para o desde esta dirección será
procesado por el sistema de correo corporativo de HEB. Tal correo
electrónico esta sujeto a ser almacenado y puede ser revisado por alguien
ajeno al recipiente autorizado con el propósito de monitorear que se cumplan
las normas de seguridad de la empresa.

More information about the Python-list mailing list