I need to find 500 digits after decimal of e. The output variable limits the number of digits to 16. How do you go forth with it?
1 Answer
Use the decimal module:
>>> import decimal >>> decimal.getcontext().prec = 501 >>> a = decimal.Decimal("2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069551702761838606261331384583000752044933826560297606737113200709328709127443747047230696977209310141692836819025515108657463772111252389784425056953696770785449969967946864454905987931636889230098793127") >>> print a 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069551702761838606261331384583000752044933826560297606737113200709328709127443747047230696977209310141692836819025515108657463772111252389784425056953696770785449969967946864454905987931636889230098793127 3 Comments
Ashtrix
Thank you so much! But I wanted to know hpw do you find this 500 digited number? As in, I know the iterative way to generate digits of e but how do I print all the 500 digits?
Tim Pietzcker
Ah, your title said 100. Well, just increase the precision to 501. Then just
print the Decimal and it will be output with all 501 digits.UlfR
If you do not want to calculate e yourself, you could get it by
decimal.Decimal(1).exp() with whatever precision you like.
floattype that can't store more digits because it has only 52 bits available to store the fraction (and 11 for the exponent, one for the sign).