| 1 |
'\" t |
| 2 |
.\" Copyright 1993 David Metcalfe ([email protected]) |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.\" References consulted: |
| 7 |
.\" Linux libc source code |
| 8 |
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) |
| 9 |
.\" 386BSD man pages |
| 10 |
.\" Modified Sat Jul 24 19:40:39 1993 by Rik Faith ([email protected]) |
| 11 |
.\" Modified Fri Jun 25 12:10:47 1999 by Andries Brouwer ([email protected]) |
| 12 |
.\" |
| 13 |
.TH ecvt 3 2024-05-02 "Linux man-pages 6.9.1" |
| 14 |
.SH NAME |
| 15 |
ecvt, fcvt \- convert a floating-point number to a string |
| 16 |
.SH LIBRARY |
| 17 |
Standard C library |
| 18 |
.RI ( libc ", " \-lc ) |
| 19 |
.SH SYNOPSIS |
| 20 |
.nf |
| 21 |
.B #include <stdlib.h> |
| 22 |
.P |
| 23 |
.BI "[[deprecated]] char *ecvt(double " number ", int " ndigits , |
| 24 |
.BI " int *restrict " decpt ", int *restrict " sign ); |
| 25 |
.BI "[[deprecated]] char *fcvt(double " number ", int " ndigits , |
| 26 |
.BI " int *restrict " decpt ", int *restrict " sign ); |
| 27 |
.fi |
| 28 |
.P |
| 29 |
.RS -4 |
| 30 |
Feature Test Macro Requirements for glibc (see |
| 31 |
.BR feature_test_macros (7)): |
| 32 |
.RE |
| 33 |
.P |
| 34 |
.BR ecvt (), |
| 35 |
.BR fcvt (): |
| 36 |
.nf |
| 37 |
Since glibc 2.17 |
| 38 |
(_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L)) |
| 39 |
|| /* glibc >= 2.20 */ _DEFAULT_SOURCE |
| 40 |
|| /* glibc <= 2.19 */ _SVID_SOURCE |
| 41 |
glibc 2.12 to glibc 2.16: |
| 42 |
(_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L)) |
| 43 |
|| _SVID_SOURCE |
| 44 |
Before glibc 2.12: |
| 45 |
_SVID_SOURCE || _XOPEN_SOURCE >= 500 |
| 46 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 47 |
.fi |
| 48 |
.SH DESCRIPTION |
| 49 |
The |
| 50 |
.BR ecvt () |
| 51 |
function converts \fInumber\fP to a null-terminated |
| 52 |
string of \fIndigits\fP digits (where \fIndigits\fP is reduced to a |
| 53 |
system-specific limit determined by the precision of a |
| 54 |
.IR double ), |
| 55 |
and returns a pointer to the string. |
| 56 |
The high-order digit is nonzero, unless |
| 57 |
.I number |
| 58 |
is zero. |
| 59 |
The low order digit is rounded. |
| 60 |
The string itself does not contain a decimal point; however, |
| 61 |
the position of the decimal point relative to the start of the string |
| 62 |
is stored in \fI*decpt\fP. |
| 63 |
A negative value for \fI*decpt\fP means that |
| 64 |
the decimal point is to the left of the start of the string. |
| 65 |
If the sign of |
| 66 |
\fInumber\fP is negative, \fI*sign\fP is set to a nonzero value, |
| 67 |
otherwise it is set to 0. |
| 68 |
If |
| 69 |
.I number |
| 70 |
is zero, it is unspecified whether \fI*decpt\fP is 0 or 1. |
| 71 |
.P |
| 72 |
The |
| 73 |
.BR fcvt () |
| 74 |
function is identical to |
| 75 |
.BR ecvt (), |
| 76 |
except that |
| 77 |
\fIndigits\fP specifies the number of digits after the decimal point. |
| 78 |
.SH RETURN VALUE |
| 79 |
Both the |
| 80 |
.BR ecvt () |
| 81 |
and |
| 82 |
.BR fcvt () |
| 83 |
functions return a pointer to a |
| 84 |
static string containing the ASCII representation of \fInumber\fP. |
| 85 |
The static string is overwritten by each call to |
| 86 |
.BR ecvt () |
| 87 |
or |
| 88 |
.BR fcvt (). |
| 89 |
.SH ATTRIBUTES |
| 90 |
For an explanation of the terms used in this section, see |
| 91 |
.BR attributes (7). |
| 92 |
.TS |
| 93 |
allbox; |
| 94 |
lbx lb lb |
| 95 |
l l l. |
| 96 |
Interface Attribute Value |
| 97 |
T{ |
| 98 |
.na |
| 99 |
.nh |
| 100 |
.BR ecvt () |
| 101 |
T} Thread safety MT-Unsafe race:ecvt |
| 102 |
T{ |
| 103 |
.na |
| 104 |
.nh |
| 105 |
.BR fcvt () |
| 106 |
T} Thread safety MT-Unsafe race:fcvt |
| 107 |
.TE |
| 108 |
.SH STANDARDS |
| 109 |
None. |
| 110 |
.SH HISTORY |
| 111 |
SVr2; |
| 112 |
marked as LEGACY in POSIX.1-2001. |
| 113 |
POSIX.1-2008 removes the specifications of |
| 114 |
.BR ecvt () |
| 115 |
and |
| 116 |
.BR fcvt (), |
| 117 |
recommending the use of |
| 118 |
.BR sprintf (3) |
| 119 |
instead (though |
| 120 |
.BR snprintf (3) |
| 121 |
may be preferable). |
| 122 |
.SH NOTES |
| 123 |
.\" Linux libc4 and libc5 specified the type of |
| 124 |
.\" .I ndigits |
| 125 |
.\" as |
| 126 |
.\" .IR size_t . |
| 127 |
Not all locales use a point as the radix character ("decimal point"). |
| 128 |
.SH SEE ALSO |
| 129 |
.BR ecvt_r (3), |
| 130 |
.BR gcvt (3), |
| 131 |
.BR qecvt (3), |
| 132 |
.BR setlocale (3), |
| 133 |
.BR sprintf (3) |