I am having problem to select contours with the following expression:

"ELEV" % 0.05=0

As I understand this should select any contour that the remainder of the division by .05 is 0. For instance, contours with an elev value of 2.1 or 2.15 or 2.2 or 2.25 should be selected. Nevertheless they are not selected. This affects the rule based symbology or labeling and select features by attributes. Contours were generated with the QGIS contour extraction tool. What I am doing wrong?

  • Floating-point equivalence is often false, just because of IEEE binary representation. Convert to integer or formatted string before comparison. – Vince Nov 21 '20 at 15:01

% is modulo operator, or the remainder term when you have done division.

Try below expression, which returns True (1) if the modulo is zero.

to_int(("ELEV" * 100) % 5) = 0

enter image description here

NB. to_int() avoids small calculation error.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.