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.
- Comparison of a float with a value in C
- Function Overloading and float in C++
- Assigning an integer to float and comparison in C/C++
- Difference between float and double in C/C++
- Modulus of two float or double numbers
- C/C++ program to find the size of int, float, double and char
- <cfloat> float.h in C/C++ with Examples
- What is the best way in C to convert a number to a string?
- Convert a floating point number to string in C
- How to convert C style strings to std::string and vice versa?
- Convert C/C++ code to assembly language
- Convert C/C++ program to Preprocessor code
- Program to Convert Hexadecimal to Octal
- Print substring of a given string without using any string function and loop in C
- Print all possible combinations of the string by replacing '$' with any other digit from the string
- std::string::crbegin() and std::string::crend() in C++ with Examples
- How to find length of a string without string.h and loop in C?
- Result of comma operator as l-value in C and C++
- Increment (Decrement) operators require L-value Expression
- How to pass an array by value in C ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.