Header File
stdlib.h
Category
Conversion Routines, Math Routines
Prototype
char *fcvt(double value, int ndig, int *dec, int *sign);
Description
Converts a floating-point number to a string.
fcvt converts value to a null-terminated string digit 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.
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, &dec, &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; }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
|
+ |
|
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|