`ecvt`

,`ecvtf`

,`fcvt`

,`fcvtf`

---double or float to string#include <stdlib.h> char *ecvt(doubleval, intchars, int *decpt, int *sgn); char *ecvtf(floatval, intchars, int *decpt, int *sgn); char *fcvt(doubleval, intdecimals, int *decpt, int *sgn); char *fcvtf(floatval, intdecimals, int *decpt, int *sgn);

**Description**

`ecvt`

and `fcvt`

produce (null-terminated) strings of digits
representating the `double`

number `val`.
`ecvtf`

and `fcvtf`

produce the corresponding character
representations of `float`

numbers.

(The `stdlib`

functions `ecvtbuf`

and `fcvtbuf`

are reentrant
versions of `ecvt`

and `fcvt`

.)

The only difference between `ecvt`

and `fcvt`

is the
interpretation of the second argument (`chars` or `decimals`).
For `ecvt`

, the second argument `chars` specifies the total number
of characters to write (which is also the number of significant digits
in the formatted string, since these two functions write only digits).
For `fcvt`

, the second argument `decimals` specifies the number of
characters to write after the decimal point; all digits for the integer
part of `val` are always included.

Since `ecvt`

and `fcvt`

write only digits in the output string,
they record the location of the decimal point in `*`

, and
the sign of the number in `decpt``*`

. After formatting a number,
`sgn``*`

contains the number of digits to the left of the
decimal point. `decpt``*`

contains `sgn``0`

if the number is positive,
and `1`

if it is negative.

**Returns**

All four functions return a pointer to the new string containing a
character representation of `val`.

**Portability**

None of these functions are ANSI C.

Supporting OS subroutines required: `close`

, `fstat`

, `isatty`

,
`lseek`

, `read`

, `sbrk`

, `write`

.

Go to the first, previous, next, last section, table of contents.