Decimals

Laszlo Nagy gandalf at designaproduct.biz
Tue Jun 13 05:53:45 EDT 2006


>> Try string formatting:
>>
>> print '%.2f' % product.price
>>     
>
> That works. I expected Python to display the data exactly as it is in
> the database, like most languages.
It depends on what you get back from MySQLdb. Try this:

import decimal
d = decimal.Decimal("3.0000")
print d


Now try this:

d = float("3.0000")
print d


The problem is -- probably -- with your db module. It may return a float 
instead of a Decimal. I cannot help more with MySQL, because I do not 
use it. Sorry.


   Laszlo




More information about the Python-list mailing list