Syntax
#include <stdlib.h> char *_fcvt(double value, int ndec, int *decptr, int *signptr);Description
If the number of digits after the decimal point in value exceeds ndec, _fcvt rounds the correct digit according to the FORTRAN F format. If there are fewer than ndec digits of precision, _fcvt pads the string with zeros.
A FORTRAN F number has the following format: ┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────────┐ │
│ │ │ │
│ >>──┬───┬────digit─┴──.────┬───────┬─┴──><
│
│ ├─+─┤ └─digit─┘ │
│ └─┴─┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
_fcvt stores only digits in the string. 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 giving the position of the decimal point with respect to the beginning of the string. A 0 or negative integer value shows that the decimal point lies to the left of the first digit.
signptr points to an integer showing the sign of value. _fcvt sets the integer to 0 if value is positive and to a nonzero number if value is negative.
_fcvt 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, computes 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 given assumes the user enters the values 2000000 and 3000.
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { float x = 2000000; float y = 3000; double z; int w,b,decimal,sign; char *buffer; z = x *y; printf("The product of %e and %e is %g.\n", x, y, z); w = log10(fabs(z))+1.; buffer = _fcvt(z, w, &decimal, &sign); b = decimal-10; if (b < 0) printf("Their product does not exceed one billion.\n"); if (b > 15) printf("The billions digit of their product is insignificant.\n"); if ((b > -1) && (b < 16)) printf("The billions digit of their product is %c.\n", buffer[b]); return 0; /**************************************************************************** The output should be: The product of 2.000000e+06 and 3.000000e+03 is 6e+09. The billions digit of their product is 6. ****************************************************************************/ }Related Information