0.3 IS NOT EQUAL 0.3 ?!?!?!

Hi everyone,

Something wired is happening.
This is my table:

Screenshot (312)

I used Math Formula to calculate sum of Column1, well obviously result was 0.3 (Column3).
Then I used Rule-based row filter to compare column2 and column3 but I faced EMPTY TABLE warning!!!

Actually it is right because in full precision renderer of column3 (sum of column1) the value is 0.30000000000000004, but why is this happening? and what is the solution?
KNIME_project3.knwf (8 KB)

PS rounding is not an option.

Tnx,
Mehrdad

Hi Mehrdad,

At the end, this is a peculiarity of floating-point operations (i.e. not KNIME-specific).

Typically you’ll want to use an “epsilon” value when you compare two numbers to avoid rounding errors, e.g. (very simplified):

EPSILON = 0.00001;
areEqual = Math.abs(value1 - value2) < EPSILON;

(note that you’ll probably have to use a “Math Formula” node instead of the “Rule” node)

More reading about floating point comparison e.g. here (it will also give reasons, why the above code might be “too simple” in general):

–Philipp

6 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.