Print this page
Minor markup tweaks (Sy instead of Nm).
fix incorrect standard citations
first round of POSIX 2008 stuff
   1 '\" te
   2 .\" Copyright 1989 AT&T.  Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.  Portions Copyright (c) 1992, X/Open Company Limited,  All Rights Reserved.
   3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   4 .\" http://www.opengroup.org/bookstore/.
   5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   6 .\"  This notice shall appear on any product containing this material.
   7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  10 .TH ECVT 3C "May 18, 2004"
  11 .SH NAME
  12 ecvt, fcvt, gcvt \- convert floating-point number to string
  13 .SH SYNOPSIS
  14 .LP
  15 .nf
  16 #include <stdlib.h>
  17 
  18 \fBchar *\fR\fBecvt\fR(\fBdouble\fR \fIvalue\fR, \fBint\fR \fIndigit\fR, \fBint *restrict\fR \fIdecpt\fR, \fBint *restrict\fR \fIsign\fR);
  19 .fi
  20 
  21 .LP
  22 .nf
  23 \fBchar *\fR\fBfcvt\fR(\fBdouble\fR \fIvalue\fR, \fBint\fR \fIndigit\fR, \fBint *restrict\fR \fIdecpt\fR, \fBint *restrict\fR \fIsign\fR);
  24 .fi
  25 
  26 .LP
  27 .nf
  28 \fBchar *\fR\fBgcvt\fR(\fBdouble\fR \fIvalue\fR, \fBint\fR \fIndigit\fR, \fBchar *\fR\fIbuf\fR);
  29 .fi
  30 
  31 .SH DESCRIPTION
  32 .sp
  33 .LP
  34 The \fBecvt()\fR, \fBfcvt()\fR and \fBgcvt()\fR functions convert
  35 floating-point numbers to null-terminated strings.
  36 .SS "\fBecvt()\fR"
  37 .sp
  38 .LP
  39 The \fBecvt()\fR function converts \fIvalue\fR to a null-terminated string of
  40 \fIndigit\fR digits (where \fIndigit\fR is reduced to an unspecified limit
  41 determined by the precision of a \fBdouble\fR) and returns a pointer to the

  42 string.  The high-order digit is non-zero, unless the value is 0.  The
  43 low-order digit is rounded.  The position of the radix character relative to
  44 the beginning of the string is stored in the integer pointed to by \fIdecpt\fR

  45 (negative means to the left of the returned digits). The radix character is not
  46 included in the returned string. If the sign of the result is negative, the
  47 integer pointed to by \fIsign\fR is non-zero, otherwise it is 0.
  48 .sp
  49 .LP

  50 If the converted value is out of range or is not representable, the contents of
  51 the returned string are unspecified.
  52 .SS "\fBfcvt()\fR"
  53 .sp
  54 .LP
  55 The \fBfcvt()\fR function is identical to \fBecvt()\fR except that \fIndigit\fR



  56 specifies the number of digits desired after the radix point.  The total number
  57 of digits in the result string is restricted to an unspecified limit as
  58 determined by the precision of a \fBdouble\fR.
  59 .SS "\fBgcvt()\fR"
  60 .sp
  61 .LP
  62 The \fBgcvt()\fR function converts \fIvalue\fR to a null-terminated string
  63 (similar to that of the \fB%g\fR format of \fBprintf\fR(3C)) in the array
  64 pointed to by \fIbuf\fR and returns \fIbuf\fR. It produces \fIndigit\fR











  65 significant digits (limited to an unspecified value determined by the precision
  66 of a \fBdouble\fR) in \fB%f\fR if possible, or \fB%e\fR (scientific notation)
  67 otherwise.  A minus sign is included in the returned string if \fIvalue\fR is
  68 less than 0.  A radix character is included in the returned string if
  69 \fIvalue\fR is not a whole number.  Trailing zeros are suppressed where
  70 \fIvalue\fR is not a whole number.  The radix character is determined by the
  71 current locale. If \fBsetlocale\fR(3C) has not been called successfully, the
  72 default locale, POSIX, is used.  The default locale specifies a period
  73 (\fB\&.\fR) as the radix character.  The \fBLC_NUMERIC\fR category determines
  74 the value of the radix character within the current locale.
  75 .SH RETURN VALUES
  76 .sp
  77 .LP
  78 The \fBecvt()\fR and \fBfcvt()\fR functions return a pointer to a
  79 null-terminated string of digits.
  80 .sp
  81 .LP
  82 The \fBgcvt()\fR function returns \fIbuf\fR.
  83 .SH ERRORS
  84 .sp
  85 .LP











  86 No errors are defined.
  87 .SH USAGE
  88 .sp
  89 .LP
  90 The return values from \fBecvt()\fR and \fBfcvt()\fR might point to


  91 thread-specific data that can be overwritten by subsequent calls to these
  92 functions by the same thread.
  93 .sp
  94 .LP
  95 For portability to implementations conforming to earlier versions of Solaris,
  96 \fBsprintf\fR(3C) is preferred over this function.
  97 .SH ATTRIBUTES
  98 .sp
  99 .LP
 100 See \fBattributes\fR(5) for descriptions of the following attributes:
 101 .sp
 102 
 103 .sp
 104 .TS
 105 box;
 106 c | c
 107 l | l .
 108 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 109 _
 110 Interface Stability     Standard
 111 _
 112 MT-Level        Safe
 113 .TE
 114 
 115 .SH SEE ALSO
 116 .sp
 117 .LP
 118 \fBprintf\fR(3C), \fBsetlocale\fR(3C), \fBsprintf\fR(3C), \fBattributes\fR(5),
 119 \fBstandards\fR(5)
   1 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
   2 .\" Copyright 1989 AT&T.  Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.  Portions Copyright (c) 1992, X/Open Company Limited,  All Rights Reserved.
   3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   4 .\" http://www.opengroup.org/bookstore/.
   5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   6 .\"  This notice shall appear on any product containing this material.
   7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  10 .Dd "Jul 19, 2014"
  11 .Dt ECVT 3C
  12 .Os
  13 .Sh NAME
  14 .Nm ecvt, fcvt, gcvt
  15 .Nd convert floating-point number to string
  16 .Sh SYNOPSIS
  17 .In stdlib.h
  18 .Ft "char *"
  19 .Fn ecvt "double value" "int ndigit" "int *restrict decpt" "int *restrict sign"
  20 .Ft "char *"
  21 .Fn fcvt "double value" "int ndigit" "int *restrict decpt" "int *restrict sign"
  22 .Ft "char *"
  23 .Fn gcvt "double value" "int ndigit" "char *buf"
  24 .Sh DESCRIPTION
  25 The
  26 .Fn ecvt ,
  27 .Fn fcvt ,
  28 and
  29 .Fn gcvt
  30 functions convert floating-point numbers to null-terminated strings.
  31 .Ss Fn ecvt
  32 The
  33 .Fn ecvt
  34 function converts
  35 .Fa value
  36 to a null-terminated string of
  37 .Fa ndigit
  38 digits (where
  39 .Fa ndigit
  40 is reduced to an unspecified limit determined by the precision of a
  41 .Ft double
  42 and returns a pointer to the
  43 string.  The high-order digit is non-zero, unless the value is 0.  The
  44 low-order digit is rounded.  The position of the radix character relative to
  45 the beginning of the string is stored in the integer pointed to by
  46 .Fa decpt
  47 (negative means to the left of the returned digits). The radix character is not
  48 included in the returned string. If the sign of the result is negative, the
  49 integer pointed to by
  50 .Fa sign
  51 is non-zero, otherwise it is 0.
  52 .Lp
  53 If the converted value is out of range or is not representable, the contents of
  54 the returned string are unspecified.
  55 .Ss Fn fcvt
  56 The
  57 .Fn fcvt
  58 function is identical to
  59 .Fn ecvt
  60 except that
  61 .Fa ndigit
  62 specifies the number of digits desired after the radix point.  The total number
  63 of digits in the result string is restricted to an unspecified limit as
  64 determined by the precision of a
  65 .Ft double .
  66 .Ss Fn gcvt
  67 The
  68 .Fn gcvt
  69 function converts
  70 .Fa value
  71 to a null-terminated string
  72 (similar to that of the
  73 .Em %g
  74 format of
  75 .Xr printf 3C
  76 in the array pointed to by
  77 .Fa buf
  78 and returns
  79 .Fa buf .
  80 It produces
  81 .Fa ndigit
  82 significant digits (limited to an unspecified value determined by the precision
  83 of a
  84 .Ft double )
  85 in
  86 .Em %f
  87 if possible, or
  88 .Em %e
  89 (scientific notation)
  90 otherwise.  A minus sign is included in the returned string if
  91 .Fa value
  92 is less than 0.  A radix character is included in the returned string if
  93 .Fa value
  94 is not a whole number.  Trailing zeros are suppressed where
  95 .Fa value
  96 is not a whole number.  The radix character is determined by the
  97 .Dv LC_NUMERIC
  98 category of the current locale.  In the default, POSIX, locale, the period
  99 .Pq Em \&.
 100 is used for the radix character.
 101 default locale, POSIX, is used.
 102 .Sh RETURN VALUES
 103 The
 104 .Fn ecvt
 105 and
 106 .Fn fcvt
 107 functions return a pointer to a null-terminated string of digits.
 108 .Lp
 109 The
 110 .Fn gcvt
 111 function returns
 112 .Fa buf .
 113 .Sh ERRORS
 114 No errors are defined.
 115 .Sh USAGE
 116 The return values from
 117 .Fn ecvt
 118 and
 119 .Fn fcvt
 120 might point to
 121 thread-specific data that can be overwritten by subsequent calls to these
 122 functions by the same thread.
 123 .Lp
 124 Portable applications should use
 125 .Xr sprintf 3C ,
 126 which is mandated by
 127 .St -isoC .
 128 .Sh INTERFACE STABILITY
 129 .Sy Obsolete Standard .
 130 .Sh MT-LEVEL
 131 .Sy Safe .
 132 .Sh SEE ALSO
 133 .Xr printf 3C ,
 134 .Xr setlocale 3C
 135 .Xr sprintf 3C ,
 136 .Xr standards 5
 137 .Sh STANDARDS
 138 These functions were introduced in
 139 .St -xpg4.2 .
 140 They were obsoleted in
 141 .St -p1003.1-2001
 142 and removed from
 143 .St -p1003.1-2008 .