Thursday 15 September 2011

Python Addition Decimal Divisions -



Python Addition Decimal Divisions -

i have range of decimal numbers dividing. when sum result of divisions, unexpected answer.

consider code below:

from decimal import decimal = decimal('3.00') a1 = decimal('15.00') b = decimal('4.00') b1 = decimal('16.00') c = decimal('7.00') c1 = decimal('31.00') a2 = / a1 b2 = b / b1 c2 = c / c1 c == + b #true c1 == a1 + b1 #true c2 == a2 + b2 #false

why c2 == a2 + b2 evaluating false?

a2 + b2 = a/a1 + b/b1 = (a*b1 + b*a1)/a1*b1

does not equal

c2 = c / c1 = (a+b) / (a1 + b1)

python

No comments:

Post a Comment