Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>atof() convert string to double</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 atof()                  Convert String to Double

 #include   <math.h>
 #include   <stdlib.h>                   Use either math.h or stdlib.h

 double     atof(string);                Value of converted string
 const char *string;      String to be converted


    atof() converts 'string' to a double-precision floating-point value.
    'string' is a sequence of characters, with the following format, that
    can be interpreted as a numeric value:

     [whitespace][sign][digits][.digits][{d|D|e|E}[sign]digits]

     where:

        whitespace  any number of tab and space characters are ignored
        sign        + or -
        digits      one or more decimal digits
        d|D|e|E     exponent prefixes

    If a decimal point is present, or if no digits appear before the
    decimal point, at least one digit must appear after the decimal
    point.  atof() stops reading input at the first character it cannot
    recognize as part of the number (likely the null character
    terminating the string).

    Returns:    The double value of 'string'.  If 'string' cannot be
                converted to a double value, then 0.0 is returned.  The
                return value is undefined for overflow; 0.0 is returned
                on underflow.

     Notes:    DBL_MAX_EXP (defined in <limits.h>) is the maximum allowed
                exponent for double values.

   -------------------------------- Example ---------------------------------

    The following statements convert several strings to double values and
    print the values.

           #include <math.h>
           #include <stdio.h>

           main()
           {
               double x, y, z;

               x = atof("    -.625d-3  (this will be -0.000625)");
               y = atof("0");
               z = atof("  143248291283472348923874.2134762734E222\n");

              /* prints: x=-6.250000e-004, y=0.000000e+000, z=1.432483e+245*/
              printf("x=%e, y=%e, z=%e\n", x, y, z);
           }


See Also: atoi() atol() ecvt() fcvt() gcvt()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson