Syntax
#include <stdlib.h> char *_ecvt(double value, int ndigits, int *decptr, int *signptr);Description
You can obtain the position of the decimal point and the sign of value after the call from decptr and signptr. decptr points to an integer value that gives the position of the decimal point with respect to the beginning of the string. A 0 or a negative integer value indicates that the decimal point lies to the left of the first digit.
signptr points to an integer that indicates the sign of the converted number. If the integer value is 0, the number is positive. If it is not 0, the number is negative.
_ecvt also converts NaN and infinity values to the strings NAN and INFINITY, respectively. For more information on NaN and infinity values, see Infinity and NaN Support.
Warning: For each thread, the _ecvt, _fcvt and _gcvt functions use a single, dynamically allocated buffer for the conversion. Any subsequent call that the same thread makes to these functions destroys the result of the previous call.
This example reads in two floating-point numbers, calculates their product, and prints out only the billions digit of its character representation. At most, 16 decimal digits of significance can be expected. The output assumes the user enters the numbers 1000000 and 3000.
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { float x,y; double z; int w,b,decimal,sign; char *buffer; printf("Enter two floating-point numbers:\n"); if (2 != scanf("%e %e", &x, &y)) { printf("input error...\n"); return EXIT_FAILURE; } z = x *y; printf("Their product is %g\n", z); w = log10(fabs(z))+1.; buffer = _ecvt(z, w, &decimal, &sign); b = decimal-10; if (b < 0) printf("Their product does not exceed one billion.\n"); else if (b > 15) printf("The billions digit of their product is insignificant.\n"); else printf("The billions digit of their product is %c.\n", buffer[b]); return 0; /**************************************************************************** For the following input: 1000000 3000 The output should be: Enter two floating-point numbers: 1000000 3000 Their product is 3e+09 The billions digit of their product is 3. ****************************************************************************/ }Related Information