Re: Really basic problem



Zentrader wrote:

You can use Python's decimal class if floating point arithmetic is not
exact enough

This is a misleading statement. While it's true that decimal can be more
precise in the sense that smaller fractions are representable, the
underlying problem of certain values not being representable properly &
leading to rounding errors still exists:



import decimal
d = decimal.Decimal
d("1") / d("3")
Decimal("0.3333333333333333333333333333")
otrd = d("1") / d("3")
otrd * 3
Decimal("0.9999999999999999999999999999")
otrd * d("3")
Decimal("0.9999999999999999999999999999")



Diez
.



Relevant Pages

  • Re: Rounding error while saving a recordset as XML
    ... I am facing one rounding error while saving a recordset as XML. ... The only fractions that are exact in base 10 are multiples of powers of 1/5 ...
    (microsoft.public.data.ado)
  • Re: Abolish Fractions?
    ... terms of decimal fractions for the purposes of the layperson. ... For practical purposes, integers suffice for almost all computations ... that must be exact, and there are decimals for the ... were cases where using fractions would be misleadingly exact anyway. ...
    (sci.math)
  • Re: Evidence of the decline in standards?
    ... I suspect he means fractions with integer numerators and denominators. ... (Irrational values tend to be left in surd form etc.) ... I had sort of lumped fractions together with using surds as a general method of working with exact numbers rather than converting to decimal... ...
    (uk.radio.amateur)