fcvt

Converts the floating-point number value into a character string

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

Syntax

  #include <stdlib.h>  
   
  char *fcvt  (  
     double   value,   
     int      ndigits,   
     int     *dec,   
     int     *sign);
  

Parameters

value
(IN) Specifies the value to be converted into a string.
ndigits
(IN) Specifies the desired total number of significant digits to the right of the decimal point.
dec
(OUT) Points to the decimal point position relative to the first digit.
sign
(OUT) Points to a positive or negative sign: 0 = Positive; Nonzero = Negative

Return Values

The fcvt function returns a pointer to a static buffer containing the converted string of digits. Note, both ecvt and fcvt use the same static buffer, except if you are using CLIB V 4.11 or above.

Remarks

The difference between the fcvt and ecvt functions is that the parameter ndigits for the fcvt function specifies the number of digits desired to the right of the decimal point. The converted number is rounded to this position.

The character string contains only digits, and it is terminated by a NULL character. The integer pointed to by dec is filled in with a value indicating the position of the decimal point relative to the start of the string of digits. A zero or negative value indicates that the decimal point lies to the left of the first digit. The integer pointed to by sign contains 0 if the number is positive, and nonzero if the number is negative.

See Also

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

Example

  #include <stdio.h>  
  #include <stdlib.h>  
   
  main()  
  {  
     char *str;  
     int  dec, sign;  
     str=fcvt( -123.456789, 5, &dec, &sign ) ;  
     printf( "str=%s, dec=%d, sign=%d\n", str,dec,sign ) ;  
  }
  

produces the following:

  str=12345679, dec=3, sign=-1