.TH ecvt() "" "" "General Function (libc)"
.PC "Convert floating-point numbers to strings"
\fBchar *\fR
\fBecvt(\fId\fB, \fIprec\^\fB, \fIdp\^\fB, \fIsignp\^\fB)\fR
\fBdouble \fId\fB; int \fIprec\^\fB, *\fIdp\^\fB, *signp\^\fB;\fR
.PP
.B ecvt()
converts
.I d
into a NUL-terminated string of numerals with the precision of
.IR prec .
Its operation resembles that of \fBprintf()\fR's
operator
.BR %e .
.PP
.B ecvt()
rounds the last digit and returns a pointer to the result.
On return,
.B ecvt()
sets
.I dp
to point to an integer that indicates the location of
the decimal point relative to the beginning of the string,
to the right if positive, to the left if negative.
It sets
.I signp
to point to an integer that indicates the sign of
.IR d ,
zero if positive and nonzero if negative.
.SH Example
The following program demonstrates
.BR ecvt() ,
.BR fcvt() ,
and
.BR gcvt() .
.DM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
.DE
.DM
/* prototypes for extended functions */
extern char *ecvt();
extern char *fcvt();
extern char *gcvt();
.DE
.DM
main(void)
{
	char buf[64];
	double d;
	int i, j;
	char *s;
.DE
.DM
	d = 1234.56789;
	s = ecvt(d, 5, &i, &j);
	/* prints ecvt="12346" i=4 j=0 */
	printf("ecvt=\e"%s\e" i=%d j=%d\en", s, i, j);
.DE
.DM
	strcpy(s, fcvt(d, 5, &i, &j));
	/* prints fcvt="123456789" i=4 j=0 */
	printf("fcvt=\e"%s\e" i=%d j=%d\en", s, i, j);
.DE
.DM
	s = gcvt(d, 5, buf);
	/* prints gcvt="1234.56789" */
	printf("gcvt=\e"%s\e"\en", s);
}
.DE
.SH "See Also"
.Xr "libc" libc
.SH Notes
.B ecvt()
performs conversions within static
string buffers that it overwrites with each execution.
