1ecvt(3) Library Functions Manual ecvt(3)
2
3
4
6 ecvt, fcvt - convert a floating-point number to a string
7
9 Standard C library (libc, -lc)
10
12 #include <stdlib.h>
13
14 [[deprecated]] char *ecvt(double number, int ndigits,
15 int *restrict decpt, int *restrict sign);
16 [[deprecated]] char *fcvt(double number, int ndigits,
17 int *restrict decpt, int *restrict sign);
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 ecvt(), fcvt():
22 Since glibc 2.17
23 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L))
24 || /* glibc >= 2.20 */ _DEFAULT_SOURCE
25 || /* glibc <= 2.19 */ _SVID_SOURCE
26 glibc 2.12 to glibc 2.16:
27 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L))
28 || _SVID_SOURCE
29 Before glibc 2.12:
30 _SVID_SOURCE || _XOPEN_SOURCE >= 500
31
33 The ecvt() function converts number to a null-terminated string of
34 ndigits digits (where ndigits is reduced to a system-specific limit de‐
35 termined by the precision of a double), and returns a pointer to the
36 string. The high-order digit is nonzero, unless number is zero. The
37 low order digit is rounded. The string itself does not contain a deci‐
38 mal point; however, the position of the decimal point relative to the
39 start of the string is stored in *decpt. A negative value for *decpt
40 means that the decimal point is to the left of the start of the string.
41 If the sign of number is negative, *sign is set to a nonzero value,
42 otherwise it is set to 0. If number is zero, it is unspecified whether
43 *decpt is 0 or 1.
44
45 The fcvt() function is identical to ecvt(), except that ndigits speci‐
46 fies the number of digits after the decimal point.
47
49 Both the ecvt() and fcvt() functions return a pointer to a static
50 string containing the ASCII representation of number. The static
51 string is overwritten by each call to ecvt() or fcvt().
52
54 For an explanation of the terms used in this section, see at‐
55 tributes(7).
56
57 ┌────────────────────────────────┬───────────────┬─────────────────────┐
58 │Interface │ Attribute │ Value │
59 ├────────────────────────────────┼───────────────┼─────────────────────┤
60 │ecvt() │ Thread safety │ MT-Unsafe race:ecvt │
61 ├────────────────────────────────┼───────────────┼─────────────────────┤
62 │fcvt() │ Thread safety │ MT-Unsafe race:fcvt │
63 └────────────────────────────────┴───────────────┴─────────────────────┘
64
66 None.
67
69 SVr2; marked as LEGACY in POSIX.1-2001. POSIX.1-2008 removes the
70 specifications of ecvt() and fcvt(), recommending the use of sprintf(3)
71 instead (though snprintf(3) may be preferable).
72
74 Not all locales use a point as the radix character ("decimal point").
75
77 ecvt_r(3), gcvt(3), qecvt(3), setlocale(3), sprintf(3)
78
79
80
81Linux man-pages 6.05 2023-07-20 ecvt(3)