Message83393
I had other code to check scale, but you are right, I should use
quantize. There is certainly a lot to absorb in the IBM decimal
specification. I really appreciate you pointing me to quantize and
Inexact. I guess I inadvertently used the issue tracker for help on
the decimal module, I didn't really mean to do that, I really thought
there was a need for Decimal.precision. The other unrelated issue I
entered (#5445) should be more of a real issue.
My code constructs a conversion/validation closure for every field in
the Schema, based on a SchemaField definition for each field. My
SchemaFieldDecimal class includes precision and scale parameters, and
now I'm going to add a rounding parameter, with None meaning raise an
error on Inexact.
So pseudo-code for the fix:
scale = None if scale is None else Decimal((0,(1,),-scale))
traps = (InvalidOperation, Inexact) if rounding is None else
(InvalidOperation,)
context = Context(prec=precision, rounding=rounding, traps=traps)
doing the conversion/validation:
For case if scale is not None:
try:
with context:
value = Decimal(value).quantize(scale)
except handlers...
For case if scale is None:
try:
with context:
value = Decimal(value)+Decimal(0) # will round or raise Inexact
except handlers... |
|
Date |
User |
Action |
Args |
2009-03-09 16:13:42 | dlesco | set | recipients:
+ dlesco, rhettinger |
2009-03-09 16:13:42 | dlesco | set | messageid: <1236615222.26.0.135415804444.issue5448@psf.upfronthosting.co.za> |
2009-03-09 16:13:41 | dlesco | link | issue5448 messages |
2009-03-09 16:13:39 | dlesco | create | |
|