Convert string to number, e.g. float with error handling

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

 While receiving UART commands, I need to convert strings to numerical values. For example, string "1.23" would produce float number 1.23 using function 'atof()':

   

V=atof('1.23…');

   

 

   

Unfortunately, in the case of a typo this function will return a valid number also ("0"), which will be passed to the program. For example:

   

 

   

atof('1.$23…')=0,    ($ is a typo)

   

 

   

Is there any built-in function to check for valid input number?

   

regards,

   

odissey1

0 Likes
11 Replies