J Jan Van Gastel Member Licensed User Aug 11, 2016 #1 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 ?
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 ?
M Mahares Expert Licensed User Longtime User Aug 11, 2016 #2 Something like one of these two: B4X: Log(NumberFormat(201/10,1,1)) 'displays: 20.1 Log($"${NumberFormat(201/10,1,1)}"$) 'displays: 20.1 Upvote 0
Something like one of these two: B4X: Log(NumberFormat(201/10,1,1)) 'displays: 20.1 Log($"${NumberFormat(201/10,1,1)}"$) 'displays: 20.1
J Jan Van Gastel Member Licensed User Aug 11, 2016 #3 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
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.
DonManfred Expert Licensed User Longtime User Aug 11, 2016 #4 Jan Van Gastel said: , so I need to convert the string to a number Click to expand... the number for THIS string is 201! Upvote 0
Jan Van Gastel said: , so I need to convert the string to a number Click to expand... the number for THIS string is 201!
nobbi59 Active Member Licensed User Longtime User Aug 11, 2016 #5 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
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
DonManfred Expert Licensed User Longtime User Aug 11, 2016 #6 nobbi59 said: You could Looop Click to expand... it will result in the number 201 too but not 20.1 Upvote 0
J Jan Van Gastel Member Licensed User Aug 11, 2016 #7 Yes, but this gives an error: B4X: Dim String1 as string = "201" Dim String2 as string String2 = NumberFormat(String1/10,1,1)) Upvote 0
Yes, but this gives an error: B4X: Dim String1 as string = "201" Dim String2 as string String2 = NumberFormat(String1/10,1,1))
Erel B4X founder Staff member Licensed User Longtime User Aug 11, 2016 #8 The above code will work after you remove the extra closing parenthesis. Upvote 0
S sorex Expert Licensed User Longtime User Aug 11, 2016 #9 in B4J this works fine B4X: Dim str1,str2 As String str1="201" str2=str1/10 Log(str2) and output 20.1 Upvote 0
in B4J this works fine B4X: Dim str1,str2 As String str1="201" str2=str1/10 Log(str2) and output 20.1