FCVT - convert float to string.

(Compatible with UNIX System V C)

Usage:

char *fcvt();
str = fcvt(value,length,decimal,sign);

Where:

double value;
is the floating point value to be converted.
int length;
is a measure of the "precision" of the string result. "fcvt" returns enough digit characters so that there would be "length" digits after the decimal point if the decimal point were added to the result string "str".
char *str;
is a string of ASCII digits ending in the usual '\0'. This string does NOT contain a sign or a decimal point. For example, if "value" is -123.45, "str" is the string "12345" with enough trailing zeroes to get a precision of "length". If "length" is less than the number of digits needed to represent "value" to full precision, the result will be rounded.
int *decimal;
points to storage for an integer. "fcvt" fills this integer with the number of digits in "str" that precede the decimal point. For example, if "value" is 123.45, "fcvt" will assign 3 to "*decimal".
int *sign;
points to storage for an integer. "fcvt" fills this integer with zero if "value" is positive or zero, and with a non-zero number if "value" is negative.

Description:

The "fcvt" function converts a floating point number into a string of digits. The sign and the position of the decimal point are indicated with values filled into "*sign" and "*decimal" point, respectively.

Below, we give some examples. In all cases, "length" is assumed to be 3.

 value      str     *decimal     *sign
 -----      ---     --------     -----
1.23456    "1235"      1          zero
-344.10   "344100"     3        non-zero
0.12345    "123"       0          zero
0.00689    "007"       0          zero

Notes:

This function comes from UNIX System V, where it was used as part of the implementation of the "printf" "%f" format specifier. On this system, however, it has nothing to do with "%f", and therefore "fcvt" and "printf" may differ on the way they convert some floating point numbers into strings.

See Also:

expl c lib ecvt

expl c lib sprintf

Copyright © 1996, Thinkage Ltd.