string - How does Python determine whether to represent a number using scientific notation or not? -


here numbers entered in python console, , resulting representations:

>>> 1 1 >>> 1.234 1.234 >>> 1.234e5 123400.0 >>> 1.234e15 1234000000000000.0 >>> 1.234e25 1.234e+25 

... , here's happens when same numbers printed:

>>> print 1 1 >>> print 1.234 1.234 >>> print 1.234e5 123400.0 >>> print 1.234e15 1.234e+15  # different! >>> print 1.234e25 1.234e+25 

how python decide representation use? why different , without print numbers?

only floating point numbers represented using scientific notation in python; integers represented as-is.

how floating point number represented in python 2.7 depends on whether it's represented using repr() (for instance, directly in console or member of collection) or str() (e.g. print statement).

with repr(), floating point numbers represented using scientific notation if either less 0.0001 (1e-4) or @ least 1e16:

>>> 1e-4 0.0001 >>> 0.00009999 9.999e-05 >>> 1e16-2 9999999999999998.0 >>> 10000000000000000.0 1e+16 

with str(), upper limit approximately 1e11:

>>> print 1e11-1 99999999999.0 >>> print 100000000000.0 1e+11 

note: in python 3, str() represents floating point numbers in same way repr().


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -