On Jan 8, 1:00 am, Paul McNett <p...@ulmcnett.com> wrote: > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be > causing > this. What would be choosing to display such a normal number in scientific > notation? > > Ideas?
[I thought I replied to this earlier, but the post isn't showing up. So here it is again.] I suspect it's your use of the Decimal normalize() method that's causing this. Trailing zeros on Decimal instances are significant, so Decimal('30.0'), Decimal('30') and Decimal('3E+1') are considered distinct (though they all have the same value). The normalize method strips all trailing zeros, turning Decimal('30.0') into Decimal('3E +1'). One way to get around this is to add 0 after normalizing: this will make sure that scientific notation is used only for very large or small numbers, as usual. Python 2.7a0 (trunk:68298:68318, Jan 6 2009, 10:39:14) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal >>> 0 + Decimal('3E1') Decimal('30') >>> Decimal('0.0') + Decimal('3E1') Decimal('30.0') Adding 0 also has the side-effect of turning a negative zero into a positive zero, but I suspect that this isn't going to worry you much. :) You might also want to look at the Decimal.quantize method. Mark -- http://mail.python.org/mailman/listinfo/python-list