Wish Add the Round2 method in B4i


Licensed User
Longtime User
In B4A and B4J we have the Round2(Number As Double, DecimalPlaces As Int)
Can you please add in B4i, if Is it possible.

Currently I use this workaround:
Private Sub Round2(Number As Double, DecimalPlaces As Int) As Double
    Private str As String
    str = NumberFormat(Number, 1, DecimalPlaces)
    Number = str
    Return Number
End Sub


B4X founder
Staff member
Licensed User
Longtime User
I would have used something like for comparisons:
Public epsilon As Double = 0.01 'constant

If Abs(d1 - d2) < epsilon Then 'they are "equal"

Much simpler than the implementation of Round2 which is:
Dim shift As Double = Power(10, DecimalPlaces)
Return Round(Number * shift) / shift
It was a mistake to add it to the core library. Its purpose was similar to NumberFormat and NumberFormat is the correct approach for conversation of numbers to strings.