ecvt() in C/C++ with Examples
This function ecvt() converts the double value to string value and returns a pointer to it. The library function defined in stdlib.h header file.
char * ecvt (double value, int num, int * dec, int * sign);
- double value: It is the double value which will convert into string.
- int num: It is a number of digits to be returned by the function.
- int * dec: It is integer pointer, which stores the decimal point position with respect to beginning the string.
- int * sign: It is integer pointer, which receives the sign indicator like 0 means positive sign and non-zero means negative.
The function return a character string terminated with null with same length specified as num that contains the digits of the double number passes as parameter.
Below is the program to illustrate the use of ecvt() function:
The converted string value is: +0.123457X10^3
Explanation: In the above C program, the double(float) value i.e., 123.4567 is converted into the string value(+ 0.123457X103) using ecvt() function.
My Personal Notes arrow_drop_up
Please Login to comment...