ecvt() Convert Double to String
#include <stdlib.h>
char *ecvt(value,ndigits,decptr,signptr);
double value; Number to be converted
int ndigits; Number of digits stored
int *decptr; Ptr to stored decimal point position
int *signptr; Pointer to stored sign indicator
ecvt() converts a floating-point number to a string. 'value' is the
number to be converted. ecvt() stores 'ndigits' number of digits of
'value' as a string and appends a null character ('\0'). If there are
more digits than 'ndigits', the low-order digit is rounded. If there
are fewer digits than 'ndgits', the string is padded with zeros.
'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. Each call to these routines destroys the
results of a previous call.
-------------------------------- 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 length = 6;
double val = 24.62941;
main()
{
string = ecvt(val,length,&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