Exponential Notation and integers

Peter Hansen peter at engcorp.com
Thu Nov 18 19:07:34 EST 2004


Erik Max Francis wrote:
> Timothy Fitz wrote:
>> Why are all numberical literals in exponential notation floats? To me
>> it is counter-intuitive for 1e3 to behave so fundamentally different
>> from 1000.
> 
> Probably primarily by convention.  Most language use computerized 
> scientific notation to represent floating point numbers, not integers. 
> It makes sense, after all:  should 1.344e3 be an int, but 1.344e2 be a 
> float?

No, naturally 1.344e2 is the integer 134.  <wink>


Maybe something like this would help the OP:

 >>> def number(x):
...    return int(float(x))
...
 >>> MYCONSTANT = number('1.344e3')
 >>> print MYCONSTANT
1344

-Peter



More information about the Python-list mailing list