Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim d As Double
Dim f As Float
d = 1800 / 1000
f = 1800 / 1000
Log("d=" & d)
Log("f=" & f)
End Sub
Always use NumberFormat or $1.2 (smart string literal) to convert numbers to strings. Binary floating point numbers cannot accurately represent decimal values.
The function "NumberFormat" does not work with Float.
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim d As Double
Dim f As Float
d = 1800 / 1001
f = 1800 / 1001
Log("d=" & d)
Log("f=" & f)
Log(" ")
d = NumberFormat(d, 1, 4)
f = NumberFormat(f, 1, 4)
Log("d=" & d)
Log("f=" & f)
End Sub
Unfortunately, I have had too many inaccuracies with the use of float, and so far I do not know where these inaccuracies come from, now it knows.
I will never use Float again in the future.