gcvt
raw OCR
Converts floating-point number to a string.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
char *gcvt(double value, int ndec, char *buf);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
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). It might suppress trailing zeros.
Return value
gcvt returns the address of the string pointed to by buf.
See also
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);
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdlib.h/gcvt/
· short form /3.1/gcvt/