Skip to content
Related Articles
Open in App
Not now

Related Articles

ecvt() in C/C++ with Examples

Improve Article
Save Article
  • Last Updated : 28 Jan, 2021
Improve Article
Save Article

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:


// C program to illustrate the
// use of ecvt() function
#include <stdio.h>
#include <stdlib.h>
// Function to illustrate the
// use of ecvt() function
void useOfEcvt()
    double x = 123.4567;
    char* buf;
    int dec, sign;
    // Function Call
    buf = ecvt(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
    return 0;


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
Related Articles

Start Your Coding Journey Now!