Unexpected scientific notation

Paul McNett p at ulmcnett.com
Fri Jan 9 18:16:35 CET 2009


Mark Dickinson wrote:
> On Jan 8, 1:00 am, Paul McNett <p... at 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.]

LOL!

> 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.

Thank you for the insight. I believe the problem is with my use of normalize(), but I 
still can't figure out why I can't reproduce the issue in my running app. But I can 
see in the interpreter that printing Decimal("30.0").normalize() results in "3E+1".

Paul



More information about the Python-list mailing list