iOS Question What is "Round2" B4A function in B4i?


Licensed User
Longtime User
I use this workaround:
#If B4i
Private Sub Round2(Number As Double, DecimalPlaces As Int) As Double
    Private shift As Double = Power(10, DecimalPlaces)
    Return Round(Number * shift) / shift
End Sub
#End If
Upvote 0


Active Member
Licensed User
I've yet to see a case where it wasn't a mistake to use Round2.
I've got a (admittedly very rare) case where using Round2 or something similar is quite useful:
A point-in-triangle test can only test if the point is really inside the triangle but fails if it lies on one of the edges. In my case, the three points of a triangle are always on some kind of a grid with equidistant spacing like 0.25 m.
Round2 helps to shift the test point very slightly (only if needed) so that the point-in-triangle test will in most cases be able to 'hit' the inside of a triangle. This approach is much more efficient than additionally testing if the point lies on an edge.
Upvote 0