Search code examples
pythonmathlong-integerscientific-notation

Python calculations without scientific notation


I have tried to use python to work with some big numbers, which hard to calculate manually. Let's say I have 2 in power of 256 as a long integer as a starting point. Then, when I want to do anything with it like divide by 2, python gives me value with scientific notation like this 5.78960446186581e+76.

However, I need very precise numbers where everything makes a difference. How can I get rid of this scientific notation, when I'm doing calculations?


Solution

  • You should use the integer division in Python 3, e. g.:

    a = 2 ** 256
    print(a / 2)
    print(a // 2)
    

    This will print

    5.78960446186581e+76
    57896044618658097711785492504343953926634992332820282019728792003956564819968