Syntax
#include <stdlib.h> char *_gcvt(double value, int ndec, char *buffer);Description
_gcvt tries to produce ndec significant digits in FORTRAN F format. Failing that, it produces ndec significant digits in FORTRAN E format. Trailing zeros might be suppressed in the conversion if they are significant.
A FORTRAN F number has the following format: ┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────────┐ │
│ │ │ │
│ >>──┬───┬────digit─┴──.────┬───────┬─┴──><
│
│ ├─+─┤ └─digit─┘ │
│ └─┴─┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
A FORTRAN E number has the following format: ┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────────┐ │
│ │ │ │
│ >>──┬───┬──digit──.────digit─┴──E──┬───┬──digit────┬───────┬─┴──><
│
│ ├─+─┤ ├─+─┤ └─digit─┘ │
│ └─┴─┘ └─┴─┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
_gcvt 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, _ecvt, _fcvt and _gcvt 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 converts the value -3.1415e3 to a character string and places it in the character array buffer1. It then converts the macro value _INF to a character string and places it in buffer2.
#include <stdio.h> #include <stdlib.h> #include <float.h> /* for the definition of _INF */ int main(void) { char buffer1[10],buffer2[10]; _gcvt(-3.1415e3, 7, buffer1); printf("The first result is %s \n", buffer1); _gcvt(_INF, 5, buffer2); printf("The second result is %s \n", buffer2); return 0; /**************************************************************************** The output should be: The first result is -3141.5 The second result is INFINITY ****************************************************************************/ }Related Information