Page 1 of 1

data conversion

Posted: Thu Nov 12, 2015 1:59 pm
by jsclownfish
How do you convert an ascii series that reports say "8.54" to an integer of "854". The decimal is giving me grief, if you use atoi you get "8". I can see it on the monitor, but I'd like to see it on the portal as well. I want to get this data type into an integer or maybe divide it by 10 and put it in a byte as a custom variable.

Thanks,
Jon

Re: data conversion

Posted: Thu Nov 12, 2015 2:41 pm
by rimai
You have to find the decimal value of each character and subtract character 0 like this:
'8'-'0' is equal to integer 8
Then you can multiply it by 10 if there is another character and ignore if it is a period.
8*10 = 80
80 + '5' - '0' = 85
85*10 = 850
850 + '4' - '0' = 854