fcvt
Converts a floating-point number to a string.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
char *fcvt(double value, int ndig, int *dec, int *sign);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
fcvt converts value to a null-terminated string digits, starting with the leftmost significant digit, with ndig digits to the right of the decimal point. fcvt then returns a pointer to the string. The position of the decimal point relative to the beginning of the string is stored indirectly through dec (a negative value for dec means to the left of the returned digits). There is no decimal point in the string itself. If the sign of value is negative, the word pointed to by sign is nonzero; otherwise, it is 0.
The correct digit has been rounded for the number of digits to the right of the decimal point specified by ndig.
Return value
The return value of fcvt points to static data whose content is overwritten by each call to fcvt and ecvt.
See also
Example
#include <stdlib.h>
#include <stdio.h>
int main(void)
char *str;
double num;
int dec, sign, ndig = 5;
/* a regular number */
num = 9.876;
str = fcvt(num, ndig, idee, &sign);
printf("string = %10s decimal place *d sign = %d\n", str, dec, sign);
/* a negative number */
num = -123.45;
str = fcvt(num, ndig, &dec, &sign);
printf("string = %10s decimal place *d sign = %d\n", str, dec, sign);
/* scientific notation */
num = 0.678e5;
str = fcvt(num, ndig, &dec, &sign);
printf("string = %10s decimal place= %d sign = %d\n", str, dec, sign);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdlib.h/fcvt/
· short form /3.1/fcvt/