Android Question Float and Double

D

Deleted member 103

Guest
Hi,

can anyone tell me why this differential output?

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 / 1000
    f = 1800 / 1000
   
    Log("d=" & d)
    Log("f=" & f)

End Sub

Log-output:
d=1.8
f=1.7999999523162842
 
D

Deleted member 103

Guest
If so, then the type "float" is not useful for me. :(
I now exchange all float variables with double.
 
Last edited by a moderator:
Upvote 0
D

Deleted member 103

Guest
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

Log-output:
d=1.7982017982017982
f=1.7982017993927002

d=1.7982
f=1.798200011253357
 
Upvote 0
D

Deleted member 103

Guest
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.
 
Upvote 0
Top