question about math module notation
Gary Herron
gherron at islandtraining.com
Thu Jul 26 22:29:39 CEST 2007
Stargaming wrote:
> On Thu, 26 Jul 2007 15:54:11 -0400, brad wrote:
>
>
>> How does one make the math module spit out actual values without using
>> engineer or scientific notation?
>>
>> I get this from <code>print math.pow(2,64)</code>: 1.84467440737e+19
>>
>> I want this:
>> 18,446,744,073,709,551,616
>>
>> I'm lazy... I don't want to convert it manually :)
>>
>
> Explicitly converting it to `int` works for me. (Without the 3-digit-
> block notation, of course.)
>
It's got nothing to do with the math module. Any floating point number,
whether produced by the math module or not, can be converted to a
printable representation using the % operator with a format string:
>>> x = 1.84467440737e+19
>>> x
1.84467440737e+19
>>> print '%25.3f' % x
18446744073699999744.000
>>> print '%12.5e' % x
1.84467e+19
>>> print '%12.5g' % x
1.8447e+19
See http://docs.python.org/lib/typesseq-strings.html for all he details.
Gary Herron
More information about the Python-list
mailing list