÷ÁÌÅÒ?Ê ÷ÏÌÏÄÉÍÉÒÏ×ÉÞ
4/13/2005 8:35:00 PM
> úù á ÞÔÏ ÚÁ ÆÕÎËÃÉÑ gcvt?
gcvt <STDLIB.H>
Converts a floating-point number to a string
Declaration
char *gcvt(double value, int ndec, char *buf);
Remarks
gcvt converts value to a null-terminated ASCII string and stores the string
in buf.
It produces ndec significant digits in FORTRAN F format, if possible.
Otherwise, it returns the value in the printf E format (ready for printing).
gcvt might suppress trailing zeros.
Return Value
On success, returns the address of the string *buf.
Portability
DOS UNIX Windows ANSI C C++ only
yes yes yes
See Also
ecvt
fcvt
sprintf
Example
gcvt example
/* gcvt example */
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char str[25];
double num;
int sig = 5; /* significant digits */
/* a regular number */
num = 9.876;
gcvt(num, sig, str);
printf("string = %s\n", str);
/* a negative number */
num = -123.4567;
gcvt(num, sig, str);
printf("string = %s\n", str);
/* scientific notation */
num = 0.678e5;
gcvt(num, sig, str);
printf("string = %s\n", str);
return(0);
}