Android Question Changing a text to a numerical value

Yves Mazzon

Member
Licensed User
Longtime User
Hello all,
I'm new with B4a so please bear with me. In my program the operator enter a value let say 2.65 in the edit text box, how can I extract the numerical value from the text to be able to use it in an equation?

many thanks.
Yves
 

Yves Mazzon

Member
Licensed User
Longtime User
1. Make sure that the string is a valid number.
2. Assign it to a floating point variable.
B4X:
Dim num As Double
If IsNumber(EditText1.Text) Then
num = EditText1.Text
End If

Many thanks Erel,
So the if condition is just to make sure a numerical value is entered. I suppose the dot of 2.65 example will be taken as a fraction too.
Regards,

Yves
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If the user is supposed to enter only numbers you should set
EditText1.InputType = EditText1.INPUT_TYPE_DECIMAL_NUMBERS
to limit the authorized characters.

EDIT: changed INPUT_TYPE_NUMBERS to INPUT_TYPE_DECIMAL_NUMBERS
 
Last edited:
Upvote 0

Yves Mazzon

Member
Licensed User
Longtime User
If the user is supposed to enter only numbers you should set
EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS
to limit the authorized characters.

Many thanks Klaus,
So I will have to assign a value to input type number to INPUT_TYPE_NUMBERS ?
something like:
dim INPUT_TYPE_NUMBERS as int
INPUT_TYPE_NUMBERS = 4 'This should take care of the dot too for a value for example of 2.65?

Regards,

Yves
 
Upvote 0
Top