Exactly the same way you compare integers:

Code:

float a=3.141, b=2.718;
if (a==b) // do something.

However there's a gotcha. Decimal conversions to binary are not precise. Try converting 0.1 yourself into binary and see what happens. The computer can only use fixed precision; it has no way of representing repeating decimals.

So floating point comparisons need to take this inaccuracy into account, e.g.:

Code:

int a=3.141, b=2.718;
if (a-b<0.005 || b-a<0.005)
// then assume it matches.

and of course you should set the value 0.005 according to the precision needed by the program. So if it's a banking program then you could set it to 1/100th of the smallest currency, for example if you're using British Sterling, where 100 pence make a pound, then you could check for less than 0.0001 (maybe). It really depends how much accuracy you need. If you need it to be exact then you need to use integers, so for instance you could store Sterling values as numbers of pence, or numbers of tenths of pence etc.