_ecvt

Description

Converts a double number to a string.

#include <stdlib.h> Required only for function declarations  

char *_ecvt( double value, int count, int *dec, int *sign );

value Number to be converted  
count Number of digits stored  
dec Stored decimal-point position  
sign Sign of converted number  

Remarks

The _ecvt function converts a floating-point number to a character string. The value argument is the floating-point number to be converted. The _ecvt function stores up to count digits of value as a string and appends a null character ('\0'). If the number of digits in value exceeds count, the low-order digit is rounded. If there are fewer than count digits, the string is padded with zeros.

Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec argument points to an integer value giving the position of the decimal point with respect to the beginning of the string. A 0 or negative integer value indicates that the decimal point lies to the left of the first digit. The sign argument points to an integer indicating the sign of the converted number. If the integer value is 0, the number is positive. Otherwise, the number is negative.

The _ecvt and _fcvt functions use a single statically allocated buffer for the conversion. Each call to one of these routines destroys the result of the previous call.

Return Value

The _ecvt function returns a pointer to the string of digits. There is no error return.

Compatibility

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use _ecvt for compatibility with ANSI naming conventions of non-ANSI functions. Use ecvt and link with OLDNAMES.LIB for UNIX compatibility.

See Also

atof, atoi, atol, _fcvt, _gcvt

Example

/* ECVT.C: This program uses _ecvt to convert a floating-point

* number to a character string.

*/

#include <stdlib.h>

#include <stdio.h>

void main( void )

{

int decimal, sign;

char *buffer;

int precision = 10;

double source = 3.1415926535;

buffer = _ecvt( source, precision, &decimal, &sign );

printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",

source, buffer, decimal, sign );

}

Output

source: 3.1415926535 buffer: '3141592654' decimal: 1 sign: 0