int dou_post(char **str_ptr)
{
int post_num = 0;
while((**str_ptr >='0')&&(**str_ptr <= '9')){
post_num = post_num * 10;
post_num += (**str_ptr - 48);
(*str_ptr)++;
}
if(**str_ptr == '.') (*str_ptr)--;
return post_num;
}
double dou_point(char **str_ptr)
{
double point_num = 0;
if((**str_ptr >='0')&&(**str_ptr <= '9')){
point_num = **str_ptr - 48;
(*str_ptr)++;
if((**str_ptr >='0')&&(**str_ptr <= '9')){
point_num += dou_point(str_ptr);
}
}
if(**str_ptr == '\0') (*str_ptr)--;
return point_num / 10;
}
// 字符串转double
double str_to_dou(char *str_ptr)
{
int post_num = 0;
double point_num = 0;
int point_flag = 0;
while(*str_ptr != '\0')
{
if(*str_ptr == '.')
point_flag = 1;
else if(point_flag == 0)
post_num =dou_post(&str_ptr);
else if(point_flag == 1)
point_num =dou_point(&str_ptr);
str_ptr++;
}
return (double)post_num + point_num;
}
c 字符串转Double
最新推荐文章于 2024-05-14 15:34:27 发布