Converts a floating-point value to a string, which it stores in a buffer.
#include <stdlib.h> | Required only for function declarations |
char *_gcvt( double value, int digits, char *buffer );
value | Value to be converted | |
digits | Number of significant digits stored | |
buffer | Storage location for result |
The _gcvt function converts a floating-point value to a character string (which includes a decimal point and a possible sign byte) and stores the string in buffer. The buffer should be large enough to accommodate the converted value plus a terminating null character ('\0'), which is appended automatically. If a buffer size of significant digits + 1 is used, the function will overwrite the end of the buffer. This is because the converted string includes a decimal point and can contain sign and exponent information. There is no provision for overflow.
The _gcvt function attempts to produce digits significant digits in decimal format. If this is not possible, it produces digits significant digits in exponential format. Trailing zeros may be suppressed in the conversion.
The _gcvt function returns a pointer to the string of digits. There is no error return.
Standards:UNIX
16-Bit:DOS, QWIN, WIN
32-Bit:DOS32X
Use _gcvt for compatibility with ANSI naming conventions of non-ANSI functions. Use gcvt and link with OLDNAMES.LIB for UNIX compatibility.
atof, atoi, atol, _ecvt, _fcvt
/* _GCVT.C: This program converts -3.1415e5 to its string representation. */
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char buffer[50];
double source = -3.1415e5;
_gcvt( source, 7, buffer );
printf( "source: %f buffer: '%s'\n", source, buffer );
_gcvt( source, 7, buffer );
printf( "source: %e buffer: '%s'\n", source, buffer );
}
source: -314150.000000 buffer: '-314150.'
source: -3.141500e+005 buffer: '-314150.'