It's all in the rounding of decimal values when stored internally in floating point form.
5.1, when stored as a float value, equates to 5.09999990463257 and thus you can see why your first comparison fails.
Your StrF() comparison is adding additional rounding errors (because you are limiting the number of decimal places) and thus you are getting a positive result this time (a false false positive!)
I may look like a mule, but I'm not a complete ass.
It has something to do with the way a Floating point variable is stored. I am not sure how it works. The example you wrote it shows that the variable UVa = 5.099999990463257 and UV=5.0 so when you subtract UV from UVa the result=0.09999999046325 that is smaller then BM wich is actualy 0.1000000014012.
The use off StrF() is logical becauce it's actualy rounded, wich is for both UVa and BM "0.100"
Relying on a string comparison following additional rounding of the floating point values is not really an ideal solution.
The following results in an incorrect comparison because of the number of decimal places being used by StrF() in this case. A spurious example I know and one that can be countered by using more places of decimals, but it still serves to show how problematic this all is.
a.f = 1.6500002
b.f = 1.6500001
If StrF(a) > StrF(b)
Debug "This should be debugged!"
EndIf
What is the exact context of the floating point comparisons? I ask because there may be a better way of proceeding depending on eactly what it is you are trying to achieve? For example, if you are comparing currency values then you stop right there!
I may look like a mule, but I'm not a complete ass.
but I use a value-to-string convesion to eliminate incertaincies of floating-point notation,
and overlook 'by accident' that both conversions use different numbers of decimals....
someone who uses strings to compare floats, and process the conversion somewhere-out-there-in-the-attic
would surely wonder why they are not equal, where the bug is.
.... it's mofo frustrating today that I seem to need to explain each and every lousefart to you... are you having your cycle?
First, don't store the currencies as floating point values - no sir!
You really want to store your currencies in an exact form. I released a currency library some time ago in the tips and tricks forum. Should be easy enough to find.