ftoa(3C)
_________________________________________________________________
ftoa function
Convert a floating-point number to a string.
_________________________________________________________________
Calling Sequence
char *ftoa(), *string, mode;
float fnum;
int precision;
ftoa(fnum, string, precision, mode);
where fnum is the floating-point number to convert.
string is a byte pointer to the beginning of a
buffer to hold the string that is the ASCII
representation of the floating-point number.
precision is the number of digits that should follow
the decimal point in the returned string. Any non-
negative value is allowed, but the maximum number of
digits that will be produced is 79.
mode specifies one of the following (note that you
must type in the single quotation marks ' '):
`e' for scientific notation.
`f' for normal notation.
`g' for either scientific or normal notation,
whichever is smaller, with nonsignificant trailing
zeros removed.
`E' is like 'e' with exponent E specified in
uppercase.
`G' is like 'g' with exponent G specified in
uppercase.
Description
Use the ftoa function to convert a floating-point number to an
ASCII string. The function places the string in a user-declared
buffer. This buffer must be 160 characters long since 160 is the
largest number of characters that ftoa will produce (when fnum =
1e75, mode = 'f', and precision >= 79).
The include file stdio.h defines this function. It also defines
a #define macro L_ftoa; L_ftoa is the maximum number of
characters that ftoa returns (160).
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
ftoa(3C)
Returns
This function returns the byte pointer to the beginning of the
string you passed.
Related Functions
See also the atof function.
Example
/* Program test for the ftoa() function */
#include <stdio.h>
FILE *fp, *fopen();
double fnum, atof();
char alf[L_ftoa], *ftoa(), mode = 'g';
int i, precision = 32;
main(argc, argv)
int argc;
char *argv[];
{
fp = fopen(argv[1], "w");
for (i = 2; i < argc; i++) {
fnum = atof(argv[i]);
ftoa(fnum, alf, precision, mode);
fprintf(fp, "%s: %16t %s\n", argv[i], alf);
}
return 0;
}
A call to the program test with the input numbers
3.14159e3
0.00002
54321.23456
6.9e4
13e-4
-3.33333
generates the output
3.14159e3: 3141.59
0.00002: 2.e-05
54321.23456: 54321.23456
6.9e4: 69000
13e-4: 0.0013
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
ftoa(3C)
-3.33333: -3.33333
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)