Python, mysql, roundoff problem?
sholden at holdenweb.com
Sun Jul 29 23:28:44 EDT 2001
"Greg Jorgensen" <gregj at pdxperts.com> wrote in message
news:%iR87.4633$Ke4.2601210 at news1.sttln1.wa.home.com...
> "William Dandreta" <wjdandreta at worldnet.att.net> wrote:
> > mysql stores numbers as strings. I discovered that when converted to
> > in Python they are not exactly the same which can cause roundoff errors.
> > floats represent money and I need to be sure there is no roundoff
> > 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
Add 0.5 then
> Divide by 100
and take the integer portion of the result
> when you need to display the value.
More information about the Python-list