gcvt
char * gcvt ( double value, int num, char * buffer ); | stdlib.h |
cplusplus.com |
Convert floating point value to string.
Converts value to a string of num digits plus
a terminating null character.
gcvt tries to generate a string with just the number in decimal
including a decimal point and, optionally, a negative sign plus.
If num digits is insufficient to express the value that way
the function will generate a number in exponential form just like the
printf %e option does. The function also appends a null-character
at the end.
So the buffer required for the resulting string is usually larger than
num characters.
Parameters.
Return Value.
A pointer to the null-terminated string of digits.
Portability.
Not defined in ANSI-C, but included in some compilers.
Example.
/* gcvt example */
#include <stdio.h>
#include <stdlib.h>
main ()
{
char buffer [20];
gcvt (1365.249,6,buffer);
puts (buffer);
gcvt (1365.249,3,buffer);
puts (buffer);
return 0;
}
Output:
1365.25
1.37e+003