Mar 27, 2003 #1 ralphtan Technical User Oct 15, 2002 15 SG Hi, if I have a char ptr with data and I want to convert to float, how can I do it? eg char* data="10000"; float F; F = *data; /* this way */
Hi, if I have a char ptr with data and I want to convert to float, how can I do it? eg char* data="10000"; float F; F = *data; /* this way */
Mar 27, 2003 #2 PieterWinter Programmer Jul 8, 2002 41 NL There are a number of possibilities: if (1 == sscanf(data,"%f",&F)) conversion OK else conversion failed OR F = atof(data) or (better) F = strtod(data,&end); The strtod provides error values when the data is out of range, or just wrong. Look at the manual page for that. HTH Pieter Upvote 0 Downvote
There are a number of possibilities: if (1 == sscanf(data,"%f",&F)) conversion OK else conversion failed OR F = atof(data) or (better) F = strtod(data,&end); The strtod provides error values when the data is out of range, or just wrong. Look at the manual page for that. HTH Pieter