#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0

    long number devision


    Hi,

    I'm just starting to learn python and need a bit of help.

    I'm just playing with the calculator functions and if i'm trying to divide a number that is too large I get the following error...

    'OverflowError: integer division result too large for a float'

    How would I go about dividing a very long number?

    Thanks
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,109
    Rep Power
    2010
    Just curious of what kind of long numbers you are working with?

    Maybe you can look at Fraction or Decimal?
    https://docs.python.org/3/library/fr...dule-fractions
    https://docs.python.org/3/library/de...module-decimal
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0
    Hi,

    It's nothing specific. I see that if I have a long number such as 502746550375606540527365703 (just something random) and I devide by 2 using /2 I get the output 2.5137327518780326e+26 which is obviously not the correct answer to the sum. I guess there is a limit to the characters that can be displayed.
    I just wondered how I'd go about working out a sum with large numbers to be calculated?

    Thanks for the reply
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    2
    Rep Power
    0
    I think that's the correct answer isn't it? The e+26 means the decimal place is moved 26 places to the right. So the real number it's showing is 251373275187803260000000000.

    So roughly speaking 502746550375606540527365703 / 2 = 25137327518780326000000000 OR 2.5137327518780326e+26

    Although I think this answer is more accurate: 251373275187803270263682851.5
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0
    Hi,

    Thanks for the explenation, the number with all the 0's i cant see how it can be used in a sum because if you take the number 25137327518780326000000000 & multiply it by 2 you get the answer 5027465503756065000000000 which is a different number to the original.

    even if you multiply the more accurate number of 251373275187803270263682851.5 you still dont get the original number. How would you go about deviding the number to give the correct result which can then be multiplied back to get the original?

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo