Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print all digits of a large number in python?

Tags:

python

numbers

So, I have a very large number that I'm working out in python, but when I try to print it I get something like this:

3.101541146879488e+80

How do I print all the digits of my lovely number?

like image 704
Nicholas D Yson Avatar asked Dec 05 '14 22:12

Nicholas D Yson


People also ask

How do you print a large integer in Python?

Try print(type(result)) and you will see it says float . You could type cast it to an integer by doing int(result) , and it will show close to the full number, 30664510802988208128 . It will be a bit off because of the memory size storage limitations of int vs float.

How do you print a full float in Python?

Solution 1: f-String Formatting Within a given f-string, you can use the {...:f} format specifier to tell Python to use floating point notation for the number preceding the :f suffix. Thus, to print the number my_float = 0.00001 non-scientifically, use the expression print(f'{my_float:f}') .


1 Answers

both int and long work for this

>>> a
3.101541146879488e+80
>>> int(a)
310154114687948792274813492416458874069290879741385354066259033875756607541870592L
>>> long(a)
310154114687948792274813492416458874069290879741385354066259033875756607541870592L
>>> print (int(a))
310154114687948792274813492416458874069290879741385354066259033875756607541870592
>>> print (long(a))
310154114687948792274813492416458874069290879741385354066259033875756607541870592
like image 81
Bhargav Rao Avatar answered Oct 25 '22 23:10

Bhargav Rao