sum - Many decimal places required in python calculations -
i need accurately sum long list of decimal numbers precision of @ least 50 decimal places. need able print sums. need unlimited decimal places.
i have no idea how this. floating numbers supposed converted strings , printed out decimal module right? have no success in understanding module or limitations. if me problem and/or maybe hint me of instructive article decimal module or floating point numbers in python, me , others.
my attempt was:
from __future__ import division decimal import * getcontext().prec = 160 summan = 0 lista = [1/4,1/3,1/5,1/6,1/7,1/9,1/10,1/11] x in lista: summan += x print decimal(str(summan))
have at documentation... fraction divisions high precision can like:
from decimal import * getcontext().prec = 160 summan = 0 lista = ['1/4','1/3','1/5','1/6','1/7','1/9','1/10','1/11'] x in lista: den, num = x.split('/') print decimal(den) / decimal(num)
Comments
Post a Comment