Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force python to print entire number

Here is my problem:

If I try for example to print the result of :

2**64

will print:

18446744073709551616L

But now if I want to print the result of :

1.8446744*10**19

This will print:

1.8446744e+19

So my question is : how can I print the entire result of 1.8446744e+19 I want to see :

18446744000000000000

And what means the sign L at the end of my numbers ?

like image 978
user2618216 Avatar asked Sep 16 '13 17:09

user2618216


2 Answers

Use string formatting to set the format you want to display:

>>> print "%.0f" % (1.8446744*10**19)
18446744000000000000
like image 179
Wooble Avatar answered Oct 15 '22 21:10

Wooble


First the L at the end of your number means the type is a 'long' you can check the type by:

>>> type(18446744000000000000)
long

Then to get your result not as a scientific notation you can just convert your number to a long:

>>> long(1.8446744*10**19)
18446744000000000000L

You can try to convert it as an int, python will automatically convert it as a long.

PS : This works only for python 2.2 and upper but not for python 3

like image 36
Freelancer Avatar answered Oct 15 '22 21:10

Freelancer