Python, mysql, roundoff problem?

William Dandreta wjdandreta at worldnet.att.net
Mon Jul 30 16:42:10 CEST 2001


Hi Greg,

I have done that in the past. The reason I asked about 64 bit integers is
because I need more than 2 decimal places. Some items are inexpensive and
sold by the 1000, i.e., $12.57 per 1000 => .01257 each.

Bill
Greg Jorgensen wrote in message
>"William Dandreta" <wjdandreta at worldnet.att.net> wrote:
>
>> mysql stores numbers as strings. I discovered that when converted to
>floats
>> in Python they are not exactly the same which can cause roundoff errors.
>The
>> floats represent money and I need to be sure there is no roundoff errors.
>>
>> What is normally done to deal with this situation?
>
>Work with pennies instead of dollars. Store 12949 instead of 129.49. Do
>integer arithmetic with pennies rather than floating-point arithmetic with
>dollars. Divide by 100 when you need to display the value.
>
>Greg Jorgensen
>PDXperts LLC
>Portland, Oregon, USA
>
>
>





More information about the Python-list mailing list