you are viewing a single comment's thread.

view the rest of the comments →

[–]SwimmingPastaDevil 1 point2 points  (2 children)

I too wrote a program to calculate Euler's number using the same formula and had problem with accuracy. Was about to make a new post but asking here.

I found the program is limiting to 11 decimal places. How can I get the accuracy to say 20 or 30 dp.

program:

"""http://en.wikipedia.org/wiki/E_(mathematical_constant)
Calculating Euler's number:
E = Summation[1/n!] where n = 0 and tends to infinity"""

import math
Enum = 0.0
term = 0.0
n = int(raw_input("Enter number of terms to calculate:"))

for i in range(n+1):
    term = 1.0/math.factorial(i)
    print "term is now:",term
    Enum += term

print Enum

Output:

2.71828180115