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