Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim D As Double = 1250.6
D = D * 100
Debug.Write(D)
Application.Exit()
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim D As Double = 1250.6
D = D * 100
Debug.Write(D)
Application.Exit()
End Sub
It is due to Java, not to B4A.
Note that you will get the right result with a float.
As D * 100 is rounded down when converted to a long, the wrong result is pretty logical for L.
If you want to control the precision, never use floats or doubles, only the BigDecimal class (in Java) or as I saw in real applications using currencies, convert everything to long for your computations and use floats or doubles only for the display (by dividing the integer value).
Right... pretty .
Note that using VB.Net, the resultS are "pretty right" anyway:
B4X:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim D As Double = 1250.6
Dim L As Long = D * 100
D = D * 100
Debug.WriteLine(D)
Debug.WriteLine(L)
Application.Exit()
End Sub
If you want to control the precision, never use floats or doubles, only the BigDecimal class (in Java) or as I saw in real applications using currencies, convert everything to long for your computations and use floats or doubles only for the display (by dividing the integer value).