The dececvt() and decfcvt() functions

The dececvt() and decfcvt() functions are analogous to the subroutines under ECVT(3) in the UNIX Programmer's Manual.

The dececvt() function works in the same fashion as the ecvt(3) function, and the decfcvt() function works in the same fashion as the fcvt(3) function. They both convert a decimal type number to a C char type value.

Syntax

char *dececvt(dec_val, ndigit, decpt, sign)
   dec_t *dec_val;
   mint ndigit;
   mint *decpt;
   mint *sign;
char *decfcvt(dec_val, ndigit, decpt, sign)
   dec_t *dec_val;
   mint ndigit;
   mint *decpt;
   mint *sign;
dec_val
A pointer to the decimal structure that contains the value to convert.
ndigit
The length of the ASCII string for dececvt(). It is the number of digits to the right of the decimal point for decfcvt().
decpt
A pointer to an integer that is the position of the decimal point relative to the start of the string. A negative or zero value for *decpt means to the left of the returned digits.
sign
A pointer to the sign of the result. If the sign of the result is negative, *sign is nonzero; otherwise, *sign is zero.

Usage

The dececvt() function converts the decimal value to which np points into a null-terminated string of ndigit ASCII digits and returns a pointer to the string. A subsequent call to this function overwrites the string.

The dececvt() function rounds low-order digits.

The decfcvt() function is identical to dececvt(), except that ndigit specifies the number of digits to the right of the decimal point instead of the total number of digits.

Let dec_val point to a decimal value of 12345.67 and suppress all arguments except ndigit. The following table shows the values that the dececvt() function returns for four different ndigit values.
ndigit value Return string *decpt value *sign
4 "1235" 5 0
10 "1234567000" 5 0
1 "1" 5 0
3 "123" 5 0