Convert Float to String in C - Convert Float Value to String using gcvt() in C Program



 Convert Float Value to String using gcvt() in C Program

Learn c - c tutorial - Convert Float Value to String using gcvt() in C Program - c examples - c programs

Convert Float Value to String using gcvt() in C Program

  • Floating point data types represent values as high-precision fractional values.
  • They usually have predefined limits on each their maximum values and their precision.
  • gcvt(): It is a library function defined in stdio.h header file. This function is used to convert a floating-point number to string.

Sample Code

#include <stdio.h>
#define MAX 50
int main()
{
    float x=245.89562f;
    char buf[MAX];
    printf("first number:245.89562");
    gcvt(x,4,buf);
    printf("\nbuffer is: %s\n",buf);
    return 0;
}

Output

first number:245.89562
buffer is: 245.9


View More Quick Examples


Related Searches to Convert Float to String in C - Convert Float Value to String using gcvt() in C Program