You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ecvtbuf.html 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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>ecvtbuf (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="ecvtbuf (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="ecvtbuf (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="_005f_005fenv_005flock.html#g_t_005f_005fenv_005flock" rel="next" title="__env_lock">
  17. <link href="gcvt.html#gcvt" rel="prev" title="gcvt">
  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="ecvtbuf"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="_005f_005fenv_005flock.html#g_t_005f_005fenv_005flock" accesskey="n" rel="next">__env_lock</a>, Previous: <a href="gcvt.html#gcvt" accesskey="p" rel="prev">gcvt</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="ecvtbuf_002c-fcvtbuf_002d_002d_002ddouble-or-float-to-string"></a>
  54. <h3 class="section">2.15 <code>ecvtbuf</code>, <code>fcvtbuf</code>&mdash;double or float to string</h3>
  55. <a name="index-ecvtbuf"></a>
  56. <a name="index-fcvtbuf"></a>
  57. <p><strong>Synopsis</strong>
  58. </p><div class="example">
  59. <pre class="example">#include &lt;stdio.h&gt;
  60. char *ecvtbuf(double <var>val</var>, int <var>chars</var>, int *<var>decpt</var>,
  61. int *<var>sgn</var>, char *<var>buf</var>);
  62. char *fcvtbuf(double <var>val</var>, int <var>decimals</var>, int *<var>decpt</var>,
  63. int *<var>sgn</var>, char *<var>buf</var>);
  64. </pre></div>
  65. <p><strong>Description</strong><br>
  66. <code>ecvtbuf</code> and <code>fcvtbuf</code> produce (null-terminated) strings
  67. of digits representating the <code>double</code> number <var>val</var>.
  68. </p>
  69. <p>The only difference between <code>ecvtbuf</code> and <code>fcvtbuf</code> is the
  70. interpretation of the second argument (<var>chars</var> or
  71. <var>decimals</var>). For <code>ecvtbuf</code>, the second argument <var>chars</var>
  72. specifies the total number of characters to write (which is
  73. also the number of significant digits in the formatted string,
  74. since these two functions write only digits). For <code>fcvtbuf</code>,
  75. the second argument <var>decimals</var> specifies the number of
  76. characters to write after the decimal point; all digits for
  77. the integer part of <var>val</var> are always included.
  78. </p>
  79. <p>Since <code>ecvtbuf</code> and <code>fcvtbuf</code> write only digits in the
  80. output string, they record the location of the decimal point
  81. in <code>*<var>decpt</var></code>, and the sign of the number in <code>*<var>sgn</var></code>.
  82. After formatting a number, <code>*<var>decpt</var></code> contains the number
  83. of digits to the left of the decimal point. <code>*<var>sgn</var></code>
  84. contains <code>0</code> if the number is positive, and <code>1</code> if it is
  85. negative. For both functions, you supply a pointer <var>buf</var> to
  86. an area of memory to hold the converted string.
  87. </p>
  88. <br>
  89. <p><strong>Returns</strong><br>
  90. Both functions return a pointer to <var>buf</var>, the string
  91. containing a character representation of <var>val</var>.
  92. </p>
  93. <br>
  94. <p><strong>Portability</strong><br>
  95. Neither function is ANSI C.
  96. </p>
  97. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  98. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  99. </p>
  100. <br>
  101. </body>
  102. </html>