Android Question String to Number or add decimal to string

Jan Van Gastel

Member
Licensed User
All,

I have a code which generates strings with info from a telnet socket.
This part is working.

I have as string with a "number" in it, for example 201.
Now in real lieve this value is 20.1 , so I need to add a decimal to it.

2 options:

- Can I convert the string to a double, float... ?
- Can I add a decimal to the string ? 201 -> 20.1 ?
 
Something like one of these two:
Code:
Log(NumberFormat(201/10,1,1))    'displays: 20.1
Log($"${NumberFormat(201/10,1,1)}"$)   'displays: 20.1
 
Upvote 0
Yes, but then I already need a double.
The "201" is in a string, so I need to convert the string to a number OR I need to put a decimal in between.
 
Upvote 0
Upvote 0
You could Looop through the string and check every char in the string if it is a number. if so you could add it to another string linke this:

dim number as string

For each c as Char in String
If Isnumber(c) then
number = number & c
end if
Next
 
Upvote 0
in B4J this works fine

Code:
Dim str1,str2 As String
str1="201"
str2=str1/10
Log(str2)

and output 20.1
 
Upvote 0
Back
Top