Search code examples
pythonscientific-notation

Python - How to not get exponent in scientific notation (e.g 1.2**1000 = 1.5179100891722457e+79)


When calculating the following 2**1000 for example you get the whole value

10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376

But if you do the same for a float i.e 1.2**1000 it gives

1.5179100891722457e+79

Is there a built-in way to get the whole value of such a calculation (Not in scientific notation)?


Solution

  • The reason for the behavior you're seeing is that the first expression results in an integer since both of its operands are integers, while the second expression is a floating point number because one of the operands is a float. To get the result you want, you can cast the result of the second expression to an int:

    >>> int(1.2**1000)
    15179100891722457049849556131606991918673074938672571271083893226004713928916992L