double atof(char s[])
{
double val, power;
int i, sign;
for (i = 0; isspace(s[i]); ++i)
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-')
++i;
for (val = 0.0; isdigit(s[i]); ++i)
val = val * 10 + s[i] - '0';
if (s[i] == '.')
i++;
for (power = 1.0; isdigits(s[i]); ++i)
{
val = val * 10 + s[i] - '0';
power *= 10;
}
return sign * val / power;
}
sting_to_double
最新推荐文章于 2023-11-17 10:14:37 发布