📄 gcvt.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>ecvt</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="ecvt"></a> <a name="tag_03_115"></a><!-- ecvt --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_115_01"></a>NAME</h4><blockquote>ecvt, fcvt, gcvt - convert a floating-point number to a string (<b>LEGACY</b>)</blockquote><h4><a name="tag_03_115_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/stdlib.h.html">stdlib.h</a>><br><br> char *ecvt(double</tt> <i>value</i><tt>, int</tt> <i>ndigit</i><tt>, int *restrict</tt> <i>decpt</i><tt>,<br> int *restrict</tt> <i>sign</i><tt>);<br> char *fcvt(double</tt> <i>value</i><tt>, int</tt> <i>ndigit</i><tt>, int *restrict</tt> <i>decpt</i><tt>,<br> int *restrict</tt> <i>sign</i><tt>);<br> char *gcvt(double</tt> <i>value</i><tt>, int</tt> <i>ndigit</i><tt>, char *</tt><i>buf</i><tt>); <img src="../images/opt-end.gif"alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_115_03"></a>DESCRIPTION</h4><blockquote><p>The <i>ecvt</i>(), <i>fcvt</i>(), and <i>gcvt</i>() functions shall convert floating-point numbers to null-terminatedstrings.</p><p>The <i>ecvt</i>() function shall convert <i>value</i> to a null-terminated string of <i>ndigit</i> digits (where <i>ndigit</i>is reduced to an unspecified limit determined by the precision of a <b>double</b>) and return a pointer to the string. Thehigh-order digit shall be non-zero, unless the value is 0. The low-order digit shall be rounded in an implementation-definedmanner. The position of the radix character relative to the beginning of the string shall be stored in the integer pointed to by<i>decpt</i> (negative means to the left of the returned digits). If <i>value</i> is zero, it is unspecified whether the integerpointed to by <i>decpt</i> would be 0 or 1. The radix character shall not be included in the returned string. If the sign of theresult is negative, the integer pointed to by <i>sign</i> shall be non-zero; otherwise, it shall be 0.</p><p>If the converted value is out of range or is not representable, the contents of the returned string are unspecified.</p><p>The <i>fcvt</i>() function shall be equivalent to <i>ecvt</i>(), except that <i>ndigit</i> specifies the number of digitsdesired after the radix character. The total number of digits in the result string is restricted to an unspecified limit asdetermined by the precision of a <b>double</b>.</p><p>The <i>gcvt</i>() function shall convert <i>value</i> to a null-terminated string (similar to that of the <tt>%g</tt> conversionspecification format of <a href="../functions/printf.html"><i>printf</i>()</a>) in the array pointed to by <i>buf</i> and shallreturn <i>buf</i>. It shall produce <i>ndigit</i> significant digits (limited to an unspecified value determined by the precisionof a <b>double</b>) in the <tt>%f</tt> conversion specification format of <a href="../functions/printf.html"><i>printf</i>()</a> ifpossible, or the <tt>%e</tt> conversion specification format of <a href="../functions/printf.html"><i>printf</i>()</a> (scientificnotation) otherwise. A minus sign shall be included in the returned string if <i>value</i> is less than 0. A radix character shallbe included in the returned string if <i>value</i> is not a whole number. Trailing zeros shall be suppressed where <i>value</i> isnot a whole number. The radix character is determined by the current locale. If <a href="../functions/setlocale.html"><i>setlocale</i>()</a> has not been called successfully, the default locale, POSIX, is used. Thedefault locale specifies a period ( <tt>'.'</tt> ) as the radix character. The <i>LC_NUMERIC</i> category determines the value ofthe radix character within the current locale.</p><p>These functions need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.</p></blockquote><h4><a name="tag_03_115_04"></a>RETURN VALUE</h4><blockquote><p>The <i>ecvt</i>() and <i>fcvt</i>() functions shall return a pointer to a null-terminated string of digits.</p><p>The <i>gcvt</i>() function shall return <i>buf</i>.</p><p>The return values from <i>ecvt</i>() and <i>fcvt</i>() may point to static data which may be overwritten by subsequent calls tothese functions.</p></blockquote><h4><a name="tag_03_115_05"></a>ERRORS</h4><blockquote><p>No errors are defined.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_115_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_115_07"></a>APPLICATION USAGE</h4><blockquote><p>The <a href="../functions/sprintf.html"><i>sprintf</i>()</a> function is preferred over this function.</p></blockquote><h4><a name="tag_03_115_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_115_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>These functions may be withdrawn in a future version.</p></blockquote><h4><a name="tag_03_115_10"></a>SEE ALSO</h4><blockquote><p><a href="printf.html"><i>printf</i>()</a> , <a href="setlocale.html"><i>setlocale</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/stdlib.h.html"><i><stdlib.h></i></a></p></blockquote><h4><a name="tag_03_115_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_115_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p><p>Normative text previously in the APPLICATION USAGE section is moved to the DESCRIPTION.</p><p>A note indicating that these functions need not be reentrant is added to the DESCRIPTION.</p></blockquote><h4><a name="tag_03_115_13"></a>Issue 6</h4><blockquote><p>In the DESCRIPTION, the note about reentrancy is expanded to cover thread-safety.</p><p>This function is marked LEGACY.</p><p>The <b>restrict</b> keyword is added to the <i>ecvt</i>() and <i>fcvt</i>() prototypes for alignment with theISO/IEC 9899:1999 standard.</p><p>The DESCRIPTION is updated to explicitly use "conversion specification" to describe <tt>%g</tt> , <tt>%f</tt> , and<tt>%e</tt> .</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -