Comment 4 for bug 881356

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Indeed, floating point values should not be compared with normal operators (except when they come directly from postgres), the usual way to do it is to subtract the 2 values and check the result against the precision limit.

For example, the res.currency object has a is_zero() method that will check that a given float value is small enough to be considered zero at the given currency precision, and can be used for all such comparisons.

The same technique should be applied here, subtract the 2 values and check that they are bigger than the "epsilon" for the current precision.

PS: for those wondering about the Decimal class, keep in mind that we don't use Decimal for OpenERP, our floating point calculations are all performed with floats, and we have appropriate solutions for all cases based on floats. So for consistency, Decimal use should not be introduced by mistake. For more info on the everlasting Float vs. Decimal discussion, see [1].

[1] https://lists.launchpad.net/openerp-expert-accounting/msg00067.html