Android Question EditBox decimal problem

elproing

Member
Hello,

I have another problem. When I insert number with decimal (3.5) in my EditBox and I insert this number in MySQL, I get 3.49990054798 in my table. Why is that?


This is my part of the code in B4A:

InsertPressureStartFRM1=FunctionBlocks.FloatWrite(EditPressureStartFRM1)

and my function wich I call


B4X:
Public Sub FloatWrite (EditFloatData As EditText) As Float

Dim FloatData As Float

If    EditFloatData.Text <> "" Then

FloatData= Round2(EditFloatData.Text,1)

Else
If EditFloatData.Text = "" Then
FloatData=0.0
End If
End If

Return FloatData

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Several mistakes in this code:
1. It is not needed.
2. Never ever use Round2.
3. Don't try to truncate the float number. Use NumberFormat or NumberFormat2 when you want to convert the number to string.

B4X:
Public Sub FloatWrite (EditFloatData As EditText) As Float
 If IsNumber(EditFloatData.Text) Then Return EditFloatData.Text
 Return 0
End Sub
Later when you want to show the number to the user use NumberFormat.
 
Upvote 0
Top