ECVT - convert float to string.

(Compatible with UNIX System V C)

Usage:

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

Where:

double value;
is the floating point value to be converted.
int length;
is the number of digits that should be in the string result.
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". The first digit is non-zero (unless "value" is zero). Trailing zeroes are added, if necessary, to pad the number out to a length of "length". If "length" is less than the number of digits needed to represent "value", the result will be rounded.
int *decimal;
points to storage for an integer. "ecvt" fills this integer with the number of digits in "str" that precede the decimal point. For example, if "value" is 123.45, "ecvt" will assign 3 to "*decimal". This number can be negative if the decimal point precedes the digits. For example, if "value" is .00123, "ecvt" will assign -2 to "*decimal".
int *sign;
points to storage for an integer. "ecvt" fills this integer with zero if "value" is positive or zero, and with a non-zero number if "value" is negative.

Description:

The "ecvt" 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 5.

 value      str     *decimal     *sign
 -----      ---     --------     -----
1.23456   "12346"      1          zero
-344.10   "34410"      3        non-zero
0.12345   "12345"      0          zero
0.06890   "68900"     -1          zero

Notes:

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

See Also:

expl c lib fcvt

expl c lib sprintf

Copyright 1996, Thinkage Ltd.