3 <<ecvt>>, <<ecvtf>>, <<fcvt>>, <<fcvtf>>---double or float to string
17 char *ecvt(double <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
18 char *ecvtf(float <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
20 char *fcvt(double <[val]>, int <[decimals]>,
21 int *<[decpt]>, int *<[sgn]>);
22 char *fcvtf(float <[val]>, int <[decimals]>,
23 int *<[decpt]>, int *<[sgn]>);
26 <<ecvt>> and <<fcvt>> produce (null-terminated) strings of digits
27 representating the <<double>> number <[val]>.
28 <<ecvtf>> and <<fcvtf>> produce the corresponding character
29 representations of <<float>> numbers.
31 (The <<stdlib>> functions <<ecvtbuf>> and <<fcvtbuf>> are reentrant
32 versions of <<ecvt>> and <<fcvt>>.)
34 The only difference between <<ecvt>> and <<fcvt>> is the
35 interpretation of the second argument (<[chars]> or <[decimals]>).
36 For <<ecvt>>, the second argument <[chars]> specifies the total number
37 of characters to write (which is also the number of significant digits
38 in the formatted string, since these two functions write only digits).
39 For <<fcvt>>, the second argument <[decimals]> specifies the number of
40 characters to write after the decimal point; all digits for the integer
41 part of <[val]> are always included.
43 Since <<ecvt>> and <<fcvt>> write only digits in the output string,
44 they record the location of the decimal point in <<*<[decpt]>>>, and
45 the sign of the number in <<*<[sgn]>>>. After formatting a number,
46 <<*<[decpt]>>> contains the number of digits to the left of the
47 decimal point. <<*<[sgn]>>> contains <<0>> if the number is positive,
48 and <<1>> if it is negative.
51 All four functions return a pointer to the new string containing a
52 character representation of <[val]>.
55 None of these functions are ANSI C.
57 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
58 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
62 <<gcvt>>, <<gcvtf>>---format double or float as string
72 char *gcvt(double <[val]>, int <[precision]>, char *<[buf]>);
73 char *gcvtf(float <[val]>, int <[precision]>, char *<[buf]>);
76 <<gcvt>> writes a fully formatted number as a null-terminated
77 string in the buffer <<*<[buf]>>>. <<gcvtf>> produces corresponding
78 character representations of <<float>> numbers.
80 <<gcvt>> uses the same rules as the <<printf>> format
81 `<<%.<[precision]>g>>'---only negative values are signed (with
82 `<<->>'), and either exponential or ordinary decimal-fraction format
83 is chosen depending on the number of significant digits (specified by
87 The result is a pointer to the formatted representation of <[val]>
88 (the same as the argument <[buf]>).
91 Neither function is ANSI C.
93 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
94 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
98 #define _XOPEN_SOURCE_EXTENDED
105 char * ecvtbuf (double, int, int*, int*, char *);
106 char * fcvtbuf (double, int, int*, int*, char *);
114 return fcvtbuf (d
, ndigit
, decpt
, sign
, NULL
);
123 return fcvt ((float) d
, ndigit
, decpt
, sign
);
138 return (_gcvt (_REENT
, d
, ndigit
, buf
, 'g', 0) ? tbuf
: 0);
148 return gcvt (asd
, ndigit
, buf
);
158 return ecvtbuf (d
, ndigit
, decpt
, sign
, NULL
);
167 return ecvt ((double) d
, ndigit
, decpt
, sign
);