1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" Modified Sat Jul 24 19:40:39 1993 by Rik Faith (faith@cs.unc.edu)
10 .\" Modified Fri Jun 25 12:10:47 1999 by Andries Brouwer (aeb@cwi.nl)
12 .TH ECVT 3 2021-03-22 GNU "Linux Programmer's Manual"
14 ecvt, fcvt \- convert a floating-point number to a string
17 .RI ( libc ", " \-lc )
20 .B #include <stdlib.h>
22 .BI "char *ecvt(double " number ", int " ndigits ", int *restrict " decpt ,
23 .BI " int *restrict " sign );
24 .BI "char *fcvt(double " number ", int " ndigits ", int *restrict " decpt ,
25 .BI " int *restrict " sign );
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
37 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L))
38 || /* Glibc >= 2.20 */ _DEFAULT_SOURCE
39 || /* Glibc <= 2.19 */ _SVID_SOURCE
40 Glibc versions 2.12 to 2.16:
41 (_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L))
44 _SVID_SOURCE || _XOPEN_SOURCE >= 500
45 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
50 function converts \fInumber\fP to a null-terminated
51 string of \fIndigits\fP digits (where \fIndigits\fP is reduced to a
52 system-specific limit determined by the precision of a
54 and returns a pointer to the string.
55 The high-order digit is nonzero, unless
58 The low order digit is rounded.
59 The string itself does not contain a decimal point; however,
60 the position of the decimal point relative to the start of the string
61 is stored in \fI*decpt\fP.
62 A negative value for \fI*decpt\fP means that
63 the decimal point is to the left of the start of the string.
65 \fInumber\fP is negative, \fI*sign\fP is set to a nonzero value,
66 otherwise it is set to 0.
69 is zero, it is unspecified whether \fI*decpt\fP is 0 or 1.
73 function is identical to
76 \fIndigits\fP specifies the number of digits after the decimal point.
82 functions return a pointer to a
83 static string containing the ASCII representation of \fInumber\fP.
84 The static string is overwritten by each call to
89 For an explanation of the terms used in this section, see
97 Interface Attribute Value
100 T} Thread safety MT-Unsafe race:ecvt
103 T} Thread safety MT-Unsafe race:fcvt
110 marked as LEGACY in POSIX.1-2001.
111 POSIX.1-2008 removes the specifications of
115 recommending the use of
121 .\" Linux libc4 and libc5 specified the type of
125 Not all locales use a point as the radix character ("decimal point").