Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ecvt.html 5.6KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>ecvt (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="ecvt (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="ecvt (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdlib.html#Stdlib" rel="up" title="Stdlib">
  16. <link href="gcvt.html#gcvt" rel="next" title="gcvt">
  17. <link href="div.html#div" rel="prev" title="div">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="ecvt"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="gcvt.html#gcvt" accesskey="n" rel="next">gcvt</a>, Previous: <a href="div.html#div" accesskey="p" rel="prev">div</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="ecvt_002c-ecvtf_002c-fcvt_002c-fcvtf_002d_002d_002ddouble-or-float-to-string"></a>
  54. <h3 class="section">2.13 <code>ecvt</code>, <code>ecvtf</code>, <code>fcvt</code>, <code>fcvtf</code>&mdash;double or float to string</h3>
  55. <a name="index-ecvt"></a>
  56. <a name="index-ecvtf"></a>
  57. <a name="index-fcvt"></a>
  58. <a name="index-fcvtf"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;stdlib.h&gt;
  62. char *ecvt(double <var>val</var>, int <var>chars</var>, int *<var>decpt</var>, int *<var>sgn</var>);
  63. char *ecvtf(float <var>val</var>, int <var>chars</var>, int *<var>decpt</var>, int *<var>sgn</var>);
  64. char *fcvt(double <var>val</var>, int <var>decimals</var>,
  65. int *<var>decpt</var>, int *<var>sgn</var>);
  66. char *fcvtf(float <var>val</var>, int <var>decimals</var>,
  67. int *<var>decpt</var>, int *<var>sgn</var>);
  68. </pre></div>
  69. <p><strong>Description</strong><br>
  70. <code>ecvt</code> and <code>fcvt</code> produce (null-terminated) strings of digits
  71. representating the <code>double</code> number <var>val</var>.
  72. <code>ecvtf</code> and <code>fcvtf</code> produce the corresponding character
  73. representations of <code>float</code> numbers.
  74. </p>
  75. <p>(The <code>stdlib</code> functions <code>ecvtbuf</code> and <code>fcvtbuf</code> are reentrant
  76. versions of <code>ecvt</code> and <code>fcvt</code>.)
  77. </p>
  78. <p>The only difference between <code>ecvt</code> and <code>fcvt</code> is the
  79. interpretation of the second argument (<var>chars</var> or <var>decimals</var>).
  80. For <code>ecvt</code>, the second argument <var>chars</var> specifies the total number
  81. of characters to write (which is also the number of significant digits
  82. in the formatted string, since these two functions write only digits).
  83. For <code>fcvt</code>, the second argument <var>decimals</var> specifies the number of
  84. characters to write after the decimal point; all digits for the integer
  85. part of <var>val</var> are always included.
  86. </p>
  87. <p>Since <code>ecvt</code> and <code>fcvt</code> write only digits in the output string,
  88. they record the location of the decimal point in <code>*<var>decpt</var></code>, and
  89. the sign of the number in <code>*<var>sgn</var></code>. After formatting a number,
  90. <code>*<var>decpt</var></code> contains the number of digits to the left of the
  91. decimal point. <code>*<var>sgn</var></code> contains <code>0</code> if the number is positive,
  92. and <code>1</code> if it is negative.
  93. </p>
  94. <br>
  95. <p><strong>Returns</strong><br>
  96. All four functions return a pointer to the new string containing a
  97. character representation of <var>val</var>.
  98. </p>
  99. <br>
  100. <p><strong>Portability</strong><br>
  101. None of these functions are ANSI C.
  102. </p>
  103. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  104. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  105. </p>
  106. <br>
  107. <br>
  108. <hr>
  109. <div class="header">
  110. <p>
  111. Next: <a href="gcvt.html#gcvt" accesskey="n" rel="next">gcvt</a>, Previous: <a href="div.html#div" accesskey="p" rel="prev">div</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  112. </div>
  113. </body>
  114. </html>