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>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, 'value', to a string
    terminated by a null character ('\0').  The string includes digits
    only.  'ndec' specifies the number of digits after the decimal point.
    If the string includes more than 'ndec' digits after the decimal
    point, the low-order digit is rounded according to the FORTRAN F
    format.  Strings including less than 'ndec' digits are padded with
    zeros.

    The position of the decimal point relative to the beginning of the
    string is given by 'decptr', an integer value.  If 'decptr' is 0 or a
    negative value, the decimal point is to the left of the first digit.
    The sign of the converted number is represented by 'signptr'--0 for a
    postive number; nonzero for a negative number.

    Returns:    A pointer to string; no error return.

      Notes:    Both fcvt() and ecvt() use a statically allocated buffer
                for conversion. Thus, a call to either routine destroys
                the results of any previous fcvt() or ecvt() call.

 Portability:   Not supported by ANSI standard.

   -------------------------------- 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: atof() atoi() atol() ecvt() gcvt()

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