C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
FCVT.C
◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
/* FCVT.C illustrates floating-point-to-string conversion functions:
* _gcvt _ecvt _fcvt
*
* See MKFPSTR.C for an example of using the data returned by _fcvt
* to build a formatted string. See ATONUM.C for an example of using
* the string returned by _gcvt.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void main()
{
int decimal, sign;
char *pnumstr;
int precision = 7;
char numbuf[50];
double number1, number2;
printf( "Enter two floating-point numbers: " );
scanf( "%lf %lf", &number1, &number2 );
/* With _gcvt, precision specifies total number of digits.
* The decimal place and sign are inserted in the string.
*/
_gcvt( number1 + number2, precision, numbuf );
printf( "\nString produced by _gcvt: %s\n", numbuf );
printf( "Total digits: %d\n", precision );
/* With _ecvt, precision specifies total number of digits.
* The decimal place and sign are provided for use in formatting.
*/
pnumstr = _ecvt( number1 + number2, precision, &decimal, &sign );
printf( "\nString produced by _ecvt: %s\nSign: %s\n",
pnumstr, sign ? "-" : "+" );
printf( "Digits left of decimal: %d\nTotal digits: %d\n",
decimal, precision );
/* With _fcvt, precision specifies digits after decimal place.
* The decimal place and sign are provided for use in formatting.
*/
pnumstr = _fcvt( number1 + number2, precision, &decimal, &sign );
printf( "\nString produced by _fcvt: %s\nSign: %s\n",
pnumstr, sign ? "-" : "+" );
printf( "Digits left of decimal: %d\nDigits after decimal: %d\n",
decimal, precision );
}
-♦-