atof()

https://en.cppreference.com/w/c/string/byte/atof
#include 
#include 
 
int main(void)
{
    printf("%g\n", atof("  -0.0000000123junk"));
    printf("%g\n", atof("0.012"));
    printf("%g\n", atof("15e16"));
    printf("%g\n", atof("-0x1afp-2"));
    printf("%g\n", atof("inF"));
    printf("%g\n", atof("Nan"));
    printf("%g\n", atof("1.0e+309"));   // UB: out of range of double
    printf("%g\n", atof("0.0"));
    printf("%g\n", atof("junk"));       // no conversion can be performed
}

Possible output:

-1.23e-08
0.012
1.5e+17
-107.75
inf
nan
inf
0
0

头文件stdlib.h,当没有转换时候就返回0

你可能感兴趣的:(C/C++)