I don't like Round2. Both Float and Double cannot 100% accurately represent all values. Using BigDecimal from BigNumber library is one option.
Another one is to use a method such as this one:
B4X:
Public Sub AreEqual(d1 As Double, d2 As Double) As Boolean
Return Abs(d1 - d2) < 0.000001
End Sub
If value1 < value2 Or AreEqual(value1, value2) Then
...
Dim Value As Float=8.21
Log(NumberFormat2(Value,1,2,0,False) <=8.20) 'FALSE'
Log(NumberFormat2(Value,1,2,0,False) <=8.21) 'TRUE'
Log(NumberFormat2(Value,1,2,0,False) <=8.22) 'TRUE'
This is quite hacky. NumberFormat returns a string which is them implicitly parsed to a number. The only reason that it works is that the implicit parsing returns a double which is the same type of the right hand side. I wouldn't consider it safe code.
The correct way to compare two floating point numbers for equality is by dealing with the expected inaccuracy.