data conversion

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

data conversion

Post 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
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: data conversion

Post 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
Roberto.
Post Reply