RAD Studio |  |

gcvt

Header File

stdlib.h

Category

Conversion Routines, Math Routines

Prototype

char *gcvt(double value, int ndec, char *buf);

Description

Converts floating-point number to a string.

gcvt converts value to a null-terminated ASCII string and stores the string in buf. It produces ndec significant digits in FORTRAN F format, if possible; otherwise, it returns the value in the printf E format (ready for printing). It might suppress trailing zeros.

Return Value

gcvt returns the address of the string pointed to by buf.

Example

Copy Code

    #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);
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
| + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!