gcvt

Converts the floating-point number value into a character string and stores the result in a buffer

Local Servers:nonblocking
Remote Servers:N/A
Classification:Other
Service:String Conversion

Syntax

  #include <stdlib.h>  
   
  char *gcvt  (  
     double   value,   
     int      ndigits,   
     char    *buffer);
  

Parameters

value
(IN) Specifies the value to be converted into a string.
ndigits
(IN) Specifies the desired total number of significant digits.
buffer
(OUT) Points to the character string.

Return Values

The gcvt function returns a pointer to the string of digits.

Remarks

The parameter ndigits specifies the number of significant digits desired. The converted number are rounded to this position.

If the exponent of the number is less than -4 or is greater than or equal to the number of significant digits wanted, then the number is converted into E-format. Otherwise, the number is formatted using F-format.

See Also

ecvt, fcvt, printf (Single and Intra-File Services)

Example

  #include <stdio.h>  
  #include <stdlib.h>  
   
  main()  
  {  
     char buffer [80] ;  
     printf( "%s\n", gcvt(-123.456789, 5, buffer ) );  
     printf( "%s\n", gcvt( 123.456789E+12, 5, buffer ) );  
  }  
  

produces the following:

  -123.46  
  1.2346E+014