_fcvt

Description

Converts a floating-point number to a string.

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

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

value Number to be converted  
count Number of digits after decimal point  
dec Pointer to stored decimal-point position  
sign Pointer to stored sign indicator  

Remarks

The _fcvt function converts a floating-point number to a null-terminated character string. The value argument is the floating-point number to be converted. The _fcvt function stores the digits of value as a string and appends a null character ('\0'). The count argument specifies the number of digits to be stored after the decimal point. Excess digits are rounded off to count places. If there are fewer than count digits of precision, 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; this integer value gives the position of the decimal point with respect to the beginning of the string. A zero or negative integer value indicates that the decimal point lies to the left of the first digit. The argument sign points to an integer indicating the sign of value. The integer is set to 0 if value is positive and is set to a nonzero number if value 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 results of the previous call.

Return Value

The _fcvt 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 _fcvt for compatibility with ANSI naming conventions of non-ANSI functions. Use fcvt and link with OLDNAMES.LIB for UNIX compatibility.

See Also

atof, atoi, atol, _ecvt, _gcvt

Example

/* FCVT.C: This program converts the constant 3.1415926535 to a string and

* sets the pointer *buffer to point to that string.

*/

#include <stdlib.h>

#include <stdio.h>

void main( void )

{

int decimal, sign;

char *buffer;

double source = 3.1415926535;

buffer = _fcvt( source, 7, &decimal, &sign );

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

source, buffer, decimal, sign );

}

Output

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