1<html lang="en"> 2<head> 3<title>ecvtbuf - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="div.html#div" title="div"> 10<link rel="next" href="ecvt.html#ecvt" title="ecvt"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="ecvtbuf"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="ecvt.html#ecvt">ecvt</a>, 31Previous: <a rel="previous" accesskey="p" href="div.html#div">div</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.15 <code>ecvtbuf</code>, <code>fcvtbuf</code>—double or float to string</h3> 37 38<p><a name="index-ecvtbuf-26"></a><a name="index-fcvtbuf-27"></a><strong>Synopsis</strong> 39<pre class="example"> #include <stdio.h> 40 41 char *ecvtbuf(double <var>val</var>, int <var>chars</var>, int *<var>decpt</var>, 42 int *<var>sgn</var>, char *<var>buf</var>); 43 44 char *fcvtbuf(double <var>val</var>, int <var>decimals</var>, int *<var>decpt</var>, 45 int *<var>sgn</var>, char *<var>buf</var>); 46 47</pre> 48 <p><strong>Description</strong><br> 49<code>ecvtbuf</code> and <code>fcvtbuf</code> produce (null-terminated) strings 50of digits representating the <code>double</code> number <var>val</var>. 51 52 <p>The only difference between <code>ecvtbuf</code> and <code>fcvtbuf</code> is the 53interpretation of the second argument (<var>chars</var> or 54<var>decimals</var>). For <code>ecvtbuf</code>, the second argument <var>chars</var> 55specifies the total number of characters to write (which is 56also the number of significant digits in the formatted string, 57since these two functions write only digits). For <code>fcvtbuf</code>, 58the second argument <var>decimals</var> specifies the number of 59characters to write after the decimal point; all digits for 60the integer part of <var>val</var> are always included. 61 62 <p>Since <code>ecvtbuf</code> and <code>fcvtbuf</code> write only digits in the 63output string, they record the location of the decimal point 64in <code>*</code><var>decpt</var>, and the sign of the number in <code>*</code><var>sgn</var>. 65After formatting a number, <code>*</code><var>decpt</var> contains the number 66of digits to the left of the decimal point. <code>*</code><var>sgn</var> 67contains <code>0</code> if the number is positive, and <code>1</code> if it is 68negative. For both functions, you supply a pointer <var>buf</var> to 69an area of memory to hold the converted string. 70 71 <p><br> 72<strong>Returns</strong><br> 73Both functions return a pointer to <var>buf</var>, the string 74containing a character representation of <var>val</var>. 75 76 <p><br> 77<strong>Portability</strong><br> 78Neither function is ANSI C. 79 80 <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>, 81<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. 82 83 <p><br> 84 85 </body></html> 86 87