iOS Question String to Float issue

SFE

Member
Licensed User
Hello
I am receiving serial data and I put it in a string called ParseData. I then try to attempt to convert the string to Float but I get an error stating it cannot Parse. If I manually assign the string to the same value there is no problem. I would think a string is a string but obviously there is some difference that I am missing

Thanks for any suggestions

Here is the value coming from my serial data that does not work.
1679447897998.png


I then added the 2nd line that reassigns to the literal value of 60.94 and that does work
1679447325925.png


The error I get when it hits the line with the float statement is
1679447366016.png
 

Attachments

  • 1679447284966.png
    1679447284966.png
    7 KB · Views: 56

emexes

Expert
Licensed User
Try adding these test lines:
B4X:
Log(RcvString)
Log(RcvString.Length)
Log(X)
ParseData=RcvString.SubString2(1,X-1)
Log(ParseData)
Log(ParseData.Length)
Log(ParseData.CompareTo("60.94"))
Log(IsNumber(ParseData))
and share (copy, paste) the Log results to this thread.

My best theory at moment is that ParseData has a non-obvious leading space. 🤔
 
Upvote 0

SFE

Member
Licensed User
You are wise beyond your years. Being a newbie I set a break point and tried to copy the 60.94 to the clipboard to view it for spaces but never could get it to copy. It never dawned on my to write the length to the log. Lesson learned the log is my friend and I will not forget it. Also pulling that leading space out it now recognizes it as a number as well.

Between this community and Erel I want to say this is the best product I have encountered. Usually I have to go it alone to figure things out.

Thank you, for the assistance it saved me some valuable time.
 
Upvote 0

SFE

Member
Licensed User
In VB6 I could fly but being in B4X I feel like I am mentally challenged : ) So having someone push me in the right direction is greatly appreciated. There are so many tools in B4X that exist problem is I just don't know they are there. Good thing for the search function on these forums.
 
Upvote 0
Top