Definition | #include <stdlib.h> char *gcvt(double value, int n, char *buf);
Depending on the structure of the floating-point value to be converted, the output format
|
Parameters | double value Floating-point value to be edited for output. int n Number of digits in the resulting string (calculated as of the first non-zero digit in the If n is less than the number of digits in value, the least significant digit is rounded. char *buf Pointer to the converted string. |
Return val. | Pointer to the converted string.
|
Notes | Invalid parameters, such as an It is your responsibility to ensure that the result pointer buf points to a memory area of at |
Example | The program reads a floating-point value x, converts it as specified in n, and outputs it as a #include <stdio.h>
#include <stdlib.h>
int main(void)
{
double x;
int n;
char *buf;
printf("Please enter floating-point number: \n");
if ( scanf("%lf",&x) == 1)
{
printf("How many significant digits : \n");
if ( scanf("%d",&n) == 1)
{
buf = (char *)malloc(n + 4);
printf("After conversion, the number is : %s \n", gcvt(x, n, buf));
}
}
return 0;
}
|
See also | ecvt, gcvt |