fcvt() Convert Double to String
#include <stdlib.h> Required for declarations only
char fcvt(value,ndec,decptr,signptr);
double value; Number to be converted
int ndec; Number of digits after decimal point
int *decptr; Pointer to decimal-point position
int *signptr; Pointer to stored sign indicator
fcvt() converts a floating-point number to a string. 'value' is the
number to be converted. fcvt() stores the digits of 'value' as a
string and appends a null character ('\0'). 'ndec' specifies the
number of digits to be stored after the decimal point. If there are
more digits than 'ndec' after the decimal point, the low-order digit
is rounded (according to the FORTRAN F format). If there are fewer
than 'ndec' digits, the string is padded with zeros.
Only digits are stored in the returned string; the position of the
decimal point and the value of the sign are returned at 'decptr' and
'signptr' respectively. 'decptr' points to an integer value giving
the position of the decimal point relative to the beginning of
'string' (0 or negative value means the decimal point is to the left
of the first digit). 'signptr' points to an integer indicating the
sign of the converted number. (A zero value means the number is
positive; any other value means the number is negative.)
Returns: A pointer to the string of digits. There is no error
return.
Notes: ecvt() and fcvt() uses a statically allocated buffer for
conversion.
A call to either of these routines destroys the results
of the previous call to either routine.
-------------------------------- Example ---------------------------------
The following statements store a double value in a string and then
print it out.
#include <stdlib.h>
int decpt, sign;
char *string;
int n_decimal_digits = 5;
double val = 24.62941;
main()
{
string = fcvt(val,n_decimal_digits,&decp,&sign);
printf("%s",string);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster