When dividing 2 large numbers in Python the output was 1.5640891676957637e+308. How do I print the entire number?
Asked
Active
Viewed 6,729 times
0
-
2Do you mean every digit of it? If it's a float, you can't, floats have limited precision. You could write your numbers as integers and use integer division `//`. But be careful when creating your numbers if you create them by converting a float to integer. – Thierry Lathuille Aug 11 '19 at 14:55
-
https://docs.python.org/3/tutorial/floatingpoint.html shows that floats only go to about 16 digits of precision. You could, theoretically, convert a float to a string and then use some arcane operations to grind out long division, but it'd take a long while. The exception would be if the large numbers only went to so many significant figures, and you could find a repeating fraction. – aschultz Aug 11 '19 at 14:57
3 Answers
5
This can't be done because that's all the precision the float
type has. It tells you the first 16 or something digits of your number and the exponent, but the digits after the first 16 have never been calculated because there's no space for them.
If you want to work with huge numbers and have basically infinite precision, almost like with Python's int
egers, try the SymPy library.

ForceBru
- 43,482
- 10
- 63
- 98
1
number_str = str(int(1.5640891676957637e+308))
print(number_str)
Prints:
156408916769576373071379516999674270294758197183972476505692635672561429946607721482839700799900977784426920800145985096418278978450607600874550703086464871105809270941181641564392002031609107640705147719606017681794554578537463358952125037388161745430586972528713238507284919924435316681000630776819257180160

Andrej Kesely
- 168,389
- 15
- 48
- 91
-
7This is only one of the many integers that would be rounded to 1.5640891676957637e+308... – Thierry Lathuille Aug 11 '19 at 14:56
0
You can consider the decimal data type in the standard library https://docs.python.org/3/library/decimal.html "The decimal module provides support for fast correctly-rounded decimal floating point arithmetic. It offers several advantages over the float datatype...Decimal numbers can be represented exactly"

lcongdon
- 36
- 4