Here, we shall see how a float number (floating point value) can be converted to the string in C language. It is a library function defined in stdio.h header file. This function is used to convert a floating point number to string.
gcvt (float value, int ndigits, char * buf); float value : It is the float or double value. int ndigits : It is number of digits. char * buf : It is character pointer, in this variable string converted value will be copied.
Input : 123.4567 Output :123.457 Input : 12345.6789 Output : 12345.7
buffer is: 123.457
Application: Following Program showing difference in output when division result are stored in
float type(result has precision upto six decimal places) in comparison to when stored directly in string type.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.