another fp problem

Michael Hall office at ninti.com
Mon Oct 6 08:27:02 EDT 2003


Hi All:

I'm a relative newbie to Python, apart from some CGI and shell scripting type
stuff. Anyway, I'm having some problems doing maths in Python 2.2.2 on RH9.

I'm wondering what is the best way or numerical data type to do simple monetary
calculations in Python? I only need to work with decimal numbers to two decimal
points. Are floating point numbers the only option? They're giving me hell!

If floating point numbers are the only option, how can I round off a number to
two decimal points? Converting to an integer is not working ... the cents disappear.

Leaving valuse as floating point is also not working ... I end up with figures
like $35.33000000018.

BTW, I'm putting values in and out of a MySQL database (DECIMAL data type) using
MySQLdb. The values giving me the most grief have been pulled out of the
database, where they look just fine.

Any advice graetly appreciated.

Mick

------------------------------------------
Ninti Systems: Linux Solutions and Support
Michael Hall
Mobile: 0429 095 392
Ph/Fax: 08 8953 1442       
Email:  office at ninti dot com
Web:    http://ninti.com
------------------------------------------





More information about the Python-list mailing list