The gcvt() function converts a floating-point number to a string. It converts given value to a null-terminated string. #include <stdlib.h> #include <stdio.h> int main(void) { char str[25]; double num; int sig = 5; /* significant digits */ /* a regular number */ num = 9.876; gcvt(num, sig, str); printf("string = %s\n", str); /* a negative number */ num = -123.4567; gcvt(num, sig, str); printf("string = %s\n", str); /* scientific notation */ num = 0.678e5; gcvt(num, sig, str); printf("string = %s\n", str); return(0); } Output:
string = 9.876
string = -123.46
string = 67800
string = 9.876
string = -123.46
string = 67800