[Tutor] precision?

Steven D'Aprano steve at pearwood.info
Tue Aug 9 17:37:24 CEST 2011


Shwinn Ricci wrote:
> When comparing a given value with a database of values, but allowing for
> freedom due to variation at say, the thousandth digit, how does one
> generalize the precision to this degree? I don't want to truncate, so is
> there a round() function that takes into account what decimal place the
> value (database value) needs to be rounded to?

Thousandth digit??? Python doesn't support floating point numbers with a 
thousand digits! I think about seventeen is about the limit.


Yes, there is a round function:


 >>> x = 123.45678
 >>> y = 123.45731
 >>> x == y
False
 >>> round(x, 3) == round(y, 3)
True




-- 
Steven



More information about the Tutor mailing list