Daniel Lescohier <daniel.lescoh...@cbs.com> added the comment: 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... ---------- message_count: 2.0 -> 3.0 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5448> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com