Please enable JavaScript to view this site.

ESL Documentation

Navigation: » No topics above this level «

Q14 How should I compare floating point values?

Scroll Prev Top Next More

To compare two floating point numbers, you really want to compare them to a specified precision. By copying a float to a string and then comparing the strings, you can accomplish this task.  The following subroutine accomplishes this:

ESLLan18

The above routine is simple and fast, but limited in that it will compare to "precision" decimal points. Another alternative is the following:

ESLLan19

This second routine has the advantage of being able to compare floats reliably to any specified number of decimal places, not just to whatever "precision" is set to for the program.