0

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
  • By the way, it's not any kind of "output variable" (which doesn't really exist) that's limiting the precision, it's the float type 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). Commented Dec 8, 2014 at 7:46

1 Answer 1

5

Use the decimal module:

>>> import decimal >>> decimal.getcontext().prec = 501 >>> a = decimal.Decimal("2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069551702761838606261331384583000752044933826560297606737113200709328709127443747047230696977209310141692836819025515108657463772111252389784425056953696770785449969967946864454905987931636889230098793127") >>> print a 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069551702761838606261331384583000752044933826560297606737113200709328709127443747047230696977209310141692836819025515108657463772111252389784425056953696770785449969967946864454905987931636889230098793127 
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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.
If you do not want to calculate e yourself, you could get it by decimal.Decimal(1).exp() with whatever precision you like.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.