Go Down

Topic: Parsing Float Values (Read 497 times) previous topic - next topic


I would like to know how I can parse the float value from a byte array or a method to parse a float value from the sd card.

I have a config file I want to use that contains a single float value on each line. The sd examples show reading the line contents into a byte array. How can I parse the float value from a byte array. Sample Data: 123.45

I searched the net and found some obscure examples none of which I could figure out or get working.  Any help would be appreciated.



You will need to figure out if it is stored in a string format ("123.45"), or in a binary format; and in the case of a binary format, how they are stored.

In the case of a string format, you read one char at a time and multiple it by 10 for each digit read and then process the dot separately. Or to use a library function.

in the case of a binary format, you typically use a union or a pointer to convert it back.


If they are ascii characters, put them in a nul-terminated string and use the atof() function.


You can use the strtok() function to throw away the part up to, and including the delimiter. Then, use strtok() again to get the token of interest, if the record contains other than just the number characters.
The art of getting good answers lies in asking good questions.

Go Up