]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ecvt.3
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[thirdparty/man-pages.git] / man3 / ecvt.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 19:40:39 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Fri Jun 25 12:10:47 1999 by Andries Brouwer (aeb@cwi.nl)
29 .\"
30 .TH ECVT 3 2010-09-20 "" "Linux Programmer's Manual"
31 .SH NAME
32 ecvt, fcvt \- convert a floating-point number to a string
33 .SH SYNOPSIS
34 .B #include <stdlib.h>
35 .sp
36 .BI "char *ecvt(double " number ", int " ndigits ", int *" decpt ,
37 .BI "int *" sign );
38 .sp
39 .BI "char *fcvt(double " number ", int " ndigits ", int *" decpt ,
40 .BI "int *" sign );
41 .sp
42 .in -4n
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .in
46 .sp
47 .BR ecvt (),
48 .BR fcvt ():
49 .ad l
50 .RS 4
51 .PD 0
52 .TP 4
53 Since glibc 2.12:
54 .nf
55 _SVID_SOURCE ||
56 (_XOPEN_SOURCE\ >=\ 500 ||
57 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
58 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
59 .fi
60 .TP 4
61 Before glibc 2.12:
62 _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
63 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
64 .PD
65 .RE
66 .ad b
67 .SH DESCRIPTION
68 The
69 .BR ecvt ()
70 function converts \fInumber\fP to a null-terminated
71 string of \fIndigits\fP digits (where \fIndigits\fP is reduced to a
72 system-specific limit determined by the precision of a
73 .IR double ),
74 and returns a pointer to the string.
75 The high-order digit is nonzero, unless
76 .I number
77 is zero.
78 The low order digit is rounded.
79 The string itself does not contain a decimal point; however,
80 the position of the decimal point relative to the start of the string
81 is stored in \fI*decpt\fP.
82 A negative value for \fI*decpt\fP means that
83 the decimal point is to the left of the start of the string.
84 If the sign of
85 \fInumber\fP is negative, \fI*sign\fP is set to a nonzero value,
86 otherwise it is set to 0.
87 If
88 .I number
89 is zero, it is unspecified whether \fI*decpt\fP is 0 or 1.
90 .PP
91 The
92 .BR fcvt ()
93 function is identical to
94 .BR ecvt (),
95 except that
96 \fIndigits\fP specifies the number of digits after the decimal point.
97 .SH RETURN VALUE
98 Both the
99 .BR ecvt ()
100 and
101 .BR fcvt ()
102 functions return a pointer to a
103 static string containing the ASCII representation of \fInumber\fP.
104 The static string is overwritten by each call to
105 .BR ecvt ()
106 or
107 .BR fcvt ().
108 .SH CONFORMING TO
109 SVr2;
110 marked as LEGACY in POSIX.1-2001.
111 POSIX.1-2008 removes the specifications of
112 .BR ecvt ()
113 and
114 .BR fcvt (),
115 recommending the use of
116 .BR sprintf (3)
117 instead (though
118 .BR snprintf (3)
119 may be preferable).
120 .SH NOTES
121 Linux libc4 and libc5 specified the type of
122 .I ndigits
123 as
124 .IR size_t .
125 Not all locales use a point as the radix character ("decimal point").
126 .SH SEE ALSO
127 .BR ecvt_r (3),
128 .BR gcvt (3),
129 .BR qecvt (3),
130 .BR setlocale (3),
131 .BR sprintf (3)