NAME
ecvt, ecvt_r, fcvt, fcvt_r, gcvt - Converts a floating-point
number to a string
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <stdlib.h>
char *ecvt (
double value,
int num_digits,
int *decimal_ptr,
int *sign );
int ecvt_r (
double value,
int num_digits,
int decimal_ptr,
int sign
char *buffer
int len );
char *fcvt (
double value,
int num_digits,
int *decimal_ptr,
int *sign );
int fcvt_r (
double value,
int num_digits,
int decimal_ptr,
int sign
char *buffer
int len );
char *gcvt (
double value,
int num_digits,
char *buffer );
PARAMETERS
value Specifies the double value to be converted.
num_digits
Specifies the number of digits in the resulting
string.
decimal_ptr
Holds the position of the decimal point relative
to the beginning of the string. A negative number
means the decimal point is to the left of the
digits given in the string.
sign Holds 0 (zero) if the value is positive or zero,
and a nonzero value if it is negative.
buffer Specifies the character array for the resulting
string.
len Specifies the length of the character array that
buffer points to.
DESCRIPTION
The ecvt(), fcvt(), and gcvt() functions convert floating-
point numbers to null-terminated strings.
The ecvt() function converts the value specified by the
value parameter to a null-terminated string of length
num_digits, and returns a pointer to it. The resulting
low-order digit is rounded according to the current rounding
mode. The decimal_ptr parameter is assigned to the position
of the decimal point relative to the position of the string.
The sign parameter is assigned 0 (zero) if value is positive
or zero, and a nonzero value if value is negative. The
decimal point and sign are not included in the string.
The fcvt() function is the same as the ecvt() function,
except that it rounds to the correct digit for outputting
num_digits digits in C or FORTRAN F-format. In the F-
format, num_digits is taken as the number of digits desired
after the decimal point.
The gcvt() function converts the value specified by the
value parameter to a null-terminated string, stores it in
the array pointed to by the buffer parameter, and then
returns buffer. The gcvt() function attempts to produce a
string of num_digits significant digits in FORTRAN F-format.
If this is not possible, then E-format is used. The string
is ready for printing, complete with minus sign, decimal
point, or exponent, as appropriate. Trailing zeros are
suppressed.
The ecvt_r() and fcvt_r() functions are the reentrant ver-
sions of the ecvt() and fcvt() functions, respectively. Upon
successful completion, the resulting string is stored in the
array pointed to by the buffer parameter, and 0 is returned.
NOTES
In the F-format, num_digits is the number of digits desired
after the decimal point. Very large numbers produce a very
long string of digits before the decimal point, and then
num_digits digits after the decimal point. For large
numbers, it is preferable to use the gcvt() or ecvt() func-
tion so that the E-format will be used.
The ecvt(), fcvt(), and gcvt() functions represent the fol-
lowing special values that are specified in ANSI/IEEE Std.
754-1985 for floating-point arithmetic:
Quiet NaN NaNQ
signalling NaN NaNS
+ Infinity
The sign associated with each of these values is stored into
the sign parameter. Note, also, that in IEEE Floating
Point, a value of 0 (zero) can be positive or negative, as
set by the sign parameter.
CAUTION
The ecvt(), fcvt(), and gcvt() functions store the strings
in a static area of memory whose contents are overwritten
each time one of the functions is called.
RELATED INFORMATION
Functions: atof(3), printf(3), scanf(3)
Acknowledgement and Disclaimer