RAD Studio
ContentsIndex
PreviousUpNext
ecvt

Header File 

stdlib.h  

Category 

Conversion Routines, Math Routines 

Prototype 

char *ecvt(double value, int ndig, int *dec, int *sign); 

Description 

Converts a floating-point number to a string. 

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 fcvt. 

Example  

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
   char *string;
   double value;
   int dec, sign;
   int 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 0;
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
 
 
 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!