Unexpected scientific notation

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Jan 7 20:56:58 EST 2009


Paul McNett <p at ulmcnett.com> writes:

> The app bundles python 2.5.2 using py2exe.
> 
> 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?

As I understand it, the Python string formatting operations
<URL:http://docs.python.org/library/stdtypes.html#string-formatting>
use the operating system's C library to perform (some of?) the
formatting.

The different behaviours you see might therefore be caused by
different C libraries in the operating system.

To avoid these and related problems, I would avoid floating point
wherever possible and use the ‘Decimal’ type for representing decimal
numbers.

-- 
 \       “For fast acting relief, try slowing down.” —Jane Wagner, via |
  `\                                                       Lily Tomlin |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list