ecvt() — Convert double to string
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>
char *ecvt(double x, int ndigit, int *__restrict__ decpt, int *__restrict__ sign);
General description
The ecvt() function converts double floating-point argument values to floating-point output strings. The ecvt() function has been extended to determine the floating-point format (hexadecimal floating-point or IEEE Binary Floating-Point) of double argument values by using __isBFP().
z/OS® XL C/C++ formatted output functions, including the ecvt() function, convert IEEE Binary Floating-Point infinity and NaN argument values to special infinity and NaN floating-point number output sequences. See “fprintf Family of Formatted Output Functions” on fprintf(), printf(), sprintf() — Format and write data for a description of the special infinity and NaN output sequences.
The ecvt() function converts x to a NULL-terminated string of ndigit digits (where ndigit is reduced to an unspecified limit determined by the precision of a double) and returns a pointer to the string. The high-order digit is nonzero, unless the value is 0. The low-order digit is rounded. The position of the radix character relative to the beginning of the string is stored in the integer pointed to by decpt (negative means left of the returned digits). The radix character is not included in the returned string. If the sign of the result is negative, the integer pointed to by sign is nonzero, otherwise it is 0.
The function returns a pointer to a buffer used only by the calling thread which may be overwritten by subsequent calls to ecvt(), fcvt() — Convert double to string and gcvt() — Convert double to string.
If the converted value is out of range or is not representable, the function returns NULL.
Returned value
If successful, ecvt() returns the character equivalent of x as specified above.
If unable to allocate the return buffer, or the conversion fails, ecvt() returns NULL.