> > I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but > > that did not lead to the correct behavior. > > Really? It works for me.
You are right, I did something wrong when attempting to set the precision. And the trick with rounding the decimal with the unary + is neat. It's the first time for me to play with decimals, so bare with me if I miss the obvious. However, this approach forces you to know the number of significant figures beforehand -- which is precisely what the arithmetics should do for you. What would indeed be nice, is Jerry's suggestion to obtain the number of significant bits and write a small wrapper around the number protocoll implementation that accounts significance and have __str__/__repr__ set the context dynamically. I haven't seen anything obvious in the docs, though it might be possible to use log10 of the length of some normalized string representation. -- http://mail.python.org/mailman/listinfo/python-list