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

 #include   <stdlib.h>                   Required for declarations only

 char       *fcvt(value,ndec,decptr,signptr);
 double     value;                       Number to be converted
 int        ndec;                        Number of digits after decimal point
 int        *decptr;                     Pointer to decimal-point position
 int        *signptr;                    Pointer to stored sign indicator


    fcvt() converts a floating-point number to a string.  'value' is the
    number to be converted.  fcvt() stores the digits of 'value' as a
    string and appends a null character ('\0').  'ndec' specifies the
    number of digits to be stored after the decimal point. If there are
    more digits than 'ndec' after the decimal point, the low-order digit
    is rounded (according to the FORTRAN F format).  If there are fewer
    than 'ndec' digits, the string is padded with zeros.

    Only digits are stored in the returned string; the position of the
    decimal point and the value of the sign are returned at 'decptr' and
    'signptr' respectively. 'decptr' points to an integer value giving
    the position of the decimal point relative to the beginning of
    'string' (0 or negative value means the decimal point is to the left
    of the first digit).  'signptr' points to an integer indicating the
    sign of the converted number. (A zero value means the number is
    positive; any other value means the number is negative.)

       Returns:     A pointer to the string of digits.  There is no error
                    return.

         Notes:     ecvt() and fcvt() use a statically allocated buffer
                    for conversion.

                    A call to either of these routines destroys the
                    results of the previous call to either routine.

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

    The following statements store a double value in a string and then
    print it out.

           #include <stdlib.h>

           int decpt, sign;
           char *string;
           int n_decimal_digits = 5;
           double val = 24.62941;

           main()
           {
               string = fcvt(val,n_decimal_digits,&decpt,&sign);
               printf("%s",string);
           }



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

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