~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to doc/interpreter/HTML/Floating_002dPoint-Conversions.html

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html lang="en">
 
2
<head>
 
3
<title>Floating-Point Conversions - Untitled</title>
 
4
<meta http-equiv="Content-Type" content="text/html">
 
5
<meta name="description" content="Untitled">
 
6
<meta name="generator" content="makeinfo 4.11">
 
7
<link title="Top" rel="start" href="index.html#Top">
 
8
<link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions">
 
9
<link rel="prev" href="Integer-Conversions.html#Integer-Conversions" title="Integer Conversions">
 
10
<link rel="next" href="Other-Output-Conversions.html#Other-Output-Conversions" title="Other Output Conversions">
 
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
</head>
 
25
<body>
 
26
<div class="node">
 
27
<p>
 
28
<a name="Floating-Point-Conversions"></a>
 
29
<a name="Floating_002dPoint-Conversions"></a>
 
30
Next:&nbsp;<a rel="next" accesskey="n" href="Other-Output-Conversions.html#Other-Output-Conversions">Other Output Conversions</a>,
 
31
Previous:&nbsp;<a rel="previous" accesskey="p" href="Integer-Conversions.html#Integer-Conversions">Integer Conversions</a>,
 
32
Up:&nbsp;<a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a>
 
33
<hr>
 
34
</div>
 
35
 
 
36
<h4 class="subsection">14.2.9 Floating-Point Conversions</h4>
 
37
 
 
38
<p>This section discusses the conversion specifications for floating-point
 
39
numbers: the &lsquo;<samp><span class="samp">%f</span></samp>&rsquo;, &lsquo;<samp><span class="samp">%e</span></samp>&rsquo;, &lsquo;<samp><span class="samp">%E</span></samp>&rsquo;, &lsquo;<samp><span class="samp">%g</span></samp>&rsquo;, and &lsquo;<samp><span class="samp">%G</span></samp>&rsquo;
 
40
conversions.
 
41
 
 
42
   <p>The &lsquo;<samp><span class="samp">%f</span></samp>&rsquo; conversion prints its argument in fixed-point notation,
 
43
producing output of the form
 
44
[<code>-</code>]<var>ddd</var><code>.</code><var>ddd</var><!-- /@w -->,
 
45
where the number of digits following the decimal point is controlled
 
46
by the precision you specify.
 
47
 
 
48
   <p>The &lsquo;<samp><span class="samp">%e</span></samp>&rsquo; conversion prints its argument in exponential notation,
 
49
producing output of the form
 
50
[<code>-</code>]<var>d</var><code>.</code><var>ddd</var><code>e</code>[<code>+</code>|<code>-</code>]<var>dd</var><!-- /@w -->. 
 
51
Again, the number of digits following the decimal point is controlled by
 
52
the precision.  The exponent always contains at least two digits.  The
 
53
&lsquo;<samp><span class="samp">%E</span></samp>&rsquo; conversion is similar but the exponent is marked with the letter
 
54
&lsquo;<samp><span class="samp">E</span></samp>&rsquo; instead of &lsquo;<samp><span class="samp">e</span></samp>&rsquo;.
 
55
 
 
56
   <p>The &lsquo;<samp><span class="samp">%g</span></samp>&rsquo; and &lsquo;<samp><span class="samp">%G</span></samp>&rsquo; conversions print the argument in the style
 
57
of &lsquo;<samp><span class="samp">%e</span></samp>&rsquo; or &lsquo;<samp><span class="samp">%E</span></samp>&rsquo; (respectively) if the exponent would be less
 
58
than -4 or greater than or equal to the precision; otherwise they use the
 
59
&lsquo;<samp><span class="samp">%f</span></samp>&rsquo; style.  Trailing zeros are removed from the fractional portion
 
60
of the result and a decimal-point character appears only if it is
 
61
followed by a digit.
 
62
 
 
63
   <p>The following flags can be used to modify the behavior:
 
64
 
 
65
<!-- Not @samp so we can have ` ' as an item. -->
 
66
     <dl>
 
67
<dt>&lsquo;<samp><span class="samp">-</span></samp>&rsquo;<dd>Left-justify the result in the field.  Normally the result is
 
68
right-justified.
 
69
 
 
70
     <br><dt>&lsquo;<samp><span class="samp">+</span></samp>&rsquo;<dd>Always include a plus or minus sign in the result.
 
71
 
 
72
     <br><dt>&lsquo;<samp> </samp>&rsquo;<dd>If the result doesn't start with a plus or minus sign, prefix it with a
 
73
space instead.  Since the &lsquo;<samp><span class="samp">+</span></samp>&rsquo; flag ensures that the result includes
 
74
a sign, this flag is ignored if you supply both of them.
 
75
 
 
76
     <br><dt>&lsquo;<samp><span class="samp">#</span></samp>&rsquo;<dd>Specifies that the result should always include a decimal point, even
 
77
if no digits follow it.  For the &lsquo;<samp><span class="samp">%g</span></samp>&rsquo; and &lsquo;<samp><span class="samp">%G</span></samp>&rsquo; conversions,
 
78
this also forces trailing zeros after the decimal point to be left
 
79
in place where they would otherwise be removed.
 
80
 
 
81
     <br><dt>&lsquo;<samp><span class="samp">0</span></samp>&rsquo;<dd>Pad the field with zeros instead of spaces; the zeros are placed
 
82
after any sign.  This flag is ignored if the &lsquo;<samp><span class="samp">-</span></samp>&rsquo; flag is also
 
83
specified. 
 
84
</dl>
 
85
 
 
86
   <p>The precision specifies how many digits follow the decimal-point
 
87
character for the &lsquo;<samp><span class="samp">%f</span></samp>&rsquo;, &lsquo;<samp><span class="samp">%e</span></samp>&rsquo;, and &lsquo;<samp><span class="samp">%E</span></samp>&rsquo; conversions.  For
 
88
these conversions, the default precision is <code>6</code>.  If the precision
 
89
is explicitly <code>0</code>, this suppresses the decimal point character
 
90
entirely.  For the &lsquo;<samp><span class="samp">%g</span></samp>&rsquo; and &lsquo;<samp><span class="samp">%G</span></samp>&rsquo; conversions, the precision
 
91
specifies how many significant digits to print.  Significant digits are
 
92
the first digit before the decimal point, and all the digits after it. 
 
93
If the precision is <code>0</code> or not specified for &lsquo;<samp><span class="samp">%g</span></samp>&rsquo; or
 
94
&lsquo;<samp><span class="samp">%G</span></samp>&rsquo;, it is treated like a value of <code>1</code>.  If the value being
 
95
printed cannot be expressed precisely in the specified number of digits,
 
96
the value is rounded to the nearest number that fits.
 
97
 
 
98
   </body></html>
 
99