fcvt() — Convert double to string

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>

char *fcvt(double x, int ndigit, int *__restrict__ decpt, int *__restrict__ sign);

General description

The fcvt() function converts double floating-point argument values to floating-point output strings. The fcvt() 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 fcvt() 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 fcvt() function converts x to a NULL-terminated string which has ndigit digits to the right of the radix point (where the total number of digits in the output string is restricted by the precision of a double) and returns a pointer to the string. The function behaves identically to ecvt() — Convert double to string in all respects other than the number of digits in the return value.

Note: This function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The sprintf() function is preferred for portability.

Returned value

If successful, fcvt() returns the character equivalent of x as specified above.

If unable to allocate the return buffer, or the conversion fails, fcvt() returns NULL.

Related information