Borland C++ reference

ecvt

raw OCR

Converts a floating-point number to a string.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
char  *ecvt(double   value, int ndig, int *dec, int *sign);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

ecvt converts value to a null-terminated string of ndig digits, starting with the leftmost significant digit, and returns a pointer to the string. The position of the decimal point relative to the beginning of the string is stored indirectly through dec (a negative value for dec means that the decimal lies to the left of the returned digits). There is no decimal point in the string itself. If the sign of value is negative, the word pointed to by sign is nonzero; otherwise, it's 0. The low-order digit is rounded.

Return value

The return value of ecvt points to static data for the string of digits whose content is overwritten by each call to ecvt and f cvt.

See also

Example

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   char * string;
   double value;
   int dec, sign, ndig = 10;
   value = 9.876;
   string = ecvt(value, ndig, &dec, &sign);
   printf("string = %s      dec = %d sign = %d\n", string, dec,  sign);
   value = -123.45;
   ndig= 15;
   string = ecvt(value,ndig,&dec,&sign);
   printf("string = %s dec = %d sign = %d\n", string, dec, sign);
   value = 0.6789e5; /* scientific notation */
   ndig = 5;
   string = ecvt(value,ndig,&dec,&sign);
   printf("string = %s           dec = %d sign = %d\n", string, dec,  sign);
return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.