Skip to main content

How in FME would you check that two floats are "close", given testing floats for equality can be a challenge?

 

e.g. "-23.123" as listed in an XLS compared to "-23.12300005" stored in a point feature class?

 

In Python I use the math.isClose() or assertAlmostEqual()

 

Thanks

 

math.isClose() uses this formula to evaluate whether two values are close or not:

abs(a-b) <= max( rel_tol * max(abs(a), abs(b)), abs_tol )

You can try implementing this formula within an AttributeManager using math operators and math functions. Using the default values for rel_tol and abs_tol, it would look something like this:

@Evaluate(@abs(@Value(fc)-@Value(xls)) <= @max(@exp(-09) * @max(@abs(@Value(fc)), @abs(@Value(xls))), 0.0))

A result of 1 would be true (close). 0 would indicate false (not close). I hope it helps!


Thanks Debbi!


Reply