On 10/06/2010 10:00 AM, Christopher Singley wrote: > [...] >> 2. store the decimals as integers, using a type with a fixed exponent. Use >> Integer, and place a TypeDecorator around it which multiplies Decimal >> objects upwards by the fixed exponent going in and back down going out. >> > Is it as simple as this? > """ > class DecimalInt(sqlalchemy.types.TypeDecorator): > impl = sqlalchemy.types.Integer > > def process_bind_param(self, value, dialect): > return int(value * 10**4) # basis pt precision > > def process_result_value(self, value, dialect): > return decimal.Decimal(value / 10**4) # basis pt precision > """ >
"value / 10**4" will either truncate to an integer (Python 2) or return a float (Python 3 or with "from __future__ import division") if value is not divisible by 10**4. I think you want "decimal.Decimal(value) / 10**4" instead. -Conor -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.