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