B4J Question Convert String to Integer or Float

derez

Expert
Licensed User
Longtime User
Just assign the string to a variable of the wanted type (after checking that the string is a number).
B4X:
Dim st as string = "543"
Dim k as int = st
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
@derez , thank you now it work. But i got too much string character. Ex "9.635287829495450" I want it to trim it to be "9.63" so How can I do?
 
Upvote 0

derez

Expert
Licensed User
Longtime User
This will give you the rounded value which is 9.64
B4X:
Dim st As String = "9.635287829495450"
Dim F As Float = st
F = NumberFormat(F,1,2)
If you want just to cut, use
B4X:
F = Floor(F*100)/100
instead of NumberFormat.
 
Upvote 0
Top