#include <stdlib.h> char * gcvt (double value, int ndigits, char *buf)
This function converts its argument value into a null-terminated
string of ndigits significant digits in buf. buf
should have enough space to hold at least ndigits + 7
characters. The result roughly corresponds to what is obtained by the
following snippet:
(void) sprintf(buf, "%.*g", ndigits, value);
except that trailing zeros and trailing decimal point are suppressed.
The least-significant digit in buf is rounded.
ecvtbuf
produces the string "NaN" if value is a NaN, and
"Inf" if value is an infinity.
A pointer to buf.
not ANSI, not POSIX
#include <stdlib.h> #include <stdio.h> #include <math.h> char vbuf[20]; /* This will print " 3.14159". */ printf ("%s", gcvt (M_PI, 5, buf));
Go to the first, previous, next, last section, table of contents.