fcvt() in C/C++ with Examples Last Updated : 26 Nov, 2021 Comments Improve Suggest changes Like Article Like Report This function fcvt() converts the floating-point value to NULL-terminated ASCII string and returns a pointer to it. It is defined in the library function defined in stdlib.h header file. Syntax: char * fcvt (double value, int num, int * dec, int * sign); Parameters: 1. double value: It is the floating-point value that will convert into a string.2. int num: It is a number of digits to be returned by the function. If this is greater than the number of digits in value then the rest of the string is padded with zeros and if it is smaller the low-order digit is rounded.3. int * dec: It is an integer pointer, which stores the decimal point position with respect to beginning the string. If it is zero or less than zero, indicates that the decimal point lies to the left of the digits4. int * sign: It is an integer pointer, which receives the sign indicator like 0 means positive sign and non-zero means negative. The function returns a character string terminated with null with the same length specified as num that contains the digits of the double number passes as a parameter. Below are the C programs to illustrate the use of fcvt() function: Example 1: C // C program to illustrate the // use of fcvt() function #include <stdio.h> #include <stdlib.h> // Function to illustrate the // use of fcvt() function void useOfFcvt() { double x = 123.4567; char* buf; int dec, sign; // Function Call buf = fcvt(x, 6, &dec, &sign); // Print the converted string printf("The converted string " "value is: %c%c.%sX10^%d\n", sign == 0 ? '+' : '-', '0', buf, dec); } // Driver Code int main() { // Function Call useOfFcvt(); return 0; } Output: The converted string value is: +0.123456700X10^3 Explanation: In the above C program, the double(float) value i.e., 123.4567 is converted into the string value(+ 0.123457X103) using fcvt() function. Example 2: C++ // C program to implement // FCVT() function #include <stdio.h> #include <stdlib.h> // Driver code int main(void) { char* string; double value; int Dec, sign; int ndig = 10; value = -9.876; string = fcvt(value, ndig, &Dec, &sign); printf("The converted string" " value is: %s Dec " "is: %d sign is: %d\n", string, Dec, sign); return 0; } Output: The converted string value is: 98760000000 Dec is: 1 sign is: 1 Comment More infoAdvertise with us Next Article fcvt() in C/C++ with Examples C CoderSaty Follow Improve Article Tags : C++ CPP-Functions C-String C-Functions cpp-strings +1 More Practice Tags : CPPcpp-strings Similar Reads ios eof() function in C++ with Examples The eof() method of ios class in C++ is used to check if the stream is has raised any EOF (End Of File) error. It means that this function will check if this stream has its eofbit set. Syntax: bool eof() const; Parameters: This method does not accept any parameter. Return Value: This method returns 1 min read ios good() function in C++ with Examples The good() method of ios class in C++ is used to check if the stream is good enough to work. It means that this function will check if this stream has raised any error or not. Syntax: bool good() const; Parameters: This method does not accept any parameter. Return Value: This method returns true if 1 min read ios operator() function in C++ with Examples The operator() method of ios class in C++ is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: operator void*() const; Parameters: This method does not accept any parameter. Return Value: This method returns a null pointer if any error bit is set of this 1 min read functional::bad_function_call in C++ with Examples Standard C++ contains several built-in exception classes, functional::bad_function_call is one of them. This is an exception thrown on bad call. Below is the syntax for the same: Header File: include<functional> Syntax: class bad_function_call; Note: To make use of functional::bad_function_cal 1 min read ctype.h(<cctype>) library in C/C++ with Examples As string.h header file contains inbuilt functions to handle Strings in C/C++, the ctype.h/<cctype> contains inbuilt functions to handle characters in C/C++ respectively. Characters are of two types: Printable Characters: The characters that are displayed on the terminal. Control Characters: T 5 min read Like