user20326: Example:
float x = 3154681.124 / 100000; //x = 31.54;

I want x to be:
x = 31.5468112;


user10794: The float type has slightly over 7 digits of precision. See https://en.wikipedia.org/wiki/Floating_point.

I want x to be:
   x = 31.5468112;


Bad luck. That's 9 digits of precision. You can get around 7 digits by converting it appropriately, eg. as Majenko said:
  float x = 3154681.124 / 100000; //x = 31.54;
  Serial.println(x, 7);

However that printed:
31.5468101

It got 7 digits right, as advertised.

You can use the BigNumber Library that I wrote. Available from GitHub.
Using that, you can get all the precision you want, within reason:
#include "BigNumber.h"

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  BigNumber::begin (7);  // 7 digits after the decimal place

  BigNumber x ("3154681.124");
  BigNumber y = x / BigNumber ("100000");
  
  Serial.println(y);
  }  // end of setup

void loop ()
  {
  }  // end of loop

Output:
31.5468112


user4143: float x = 3154681.124 / 100000; //x = 31.54;

x is now 31.5468112 (or close to).
Serial.println(x);

Output: 31.54
Why? Because Serial.println defaults to 2 decimal places for floats.

Syntax
Serial.println(val)
Serial.println(val, format)
Parameters
val: the value to print - any data type
format: specifies the number base (for integral data types) or number of decimal places (for floating point types)

So the solution: specift 7 decimal places when you print:
Serial.println(x, 7);


20326: <p>Example:</p>

<pre><code>float x = 3154681.124 / 100000; //x = 31.54;
</code></pre>

<p>I want x to be:</p>

<pre><code>x = 31.5468112;
</code></pre>
 10794: <p>The <code>float</code> type has slightly over 7 digits of precision. See <a href="https://en.wikipedia.org/wiki/Floating_point" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Floating_point</a>.</p>
<blockquote>
<p>I want x to be:</p>
<pre><code>   x = 31.5468112;
</code></pre>
</blockquote>
<p>Bad luck. That's 9 digits of precision. You can get around 7 digits by converting it appropriately, eg. as Majenko said:</p>
<pre class="lang-c++ prettyprint-override"><code>  float x = 3154681.124 / 100000; //x = 31.54;
  Serial.println(x, 7);
</code></pre>
<p>However that printed:</p>
<pre><code>31.5468101
</code></pre>
<p>It got 7 digits right, as advertised.</p>
<hr />
<p>You can use the <a href="http://www.gammon.com.au/forum/?id=11519" rel="nofollow noreferrer">BigNumber Library</a> that I wrote. Available from <a href="https://github.com/nickgammon/BigNumber" rel="nofollow noreferrer">GitHub</a>.</p>
<p>Using that, you can get all the precision you want, within reason:</p>
<pre><code>#include &quot;BigNumber.h&quot;

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  BigNumber::begin (7);  // 7 digits after the decimal place

  BigNumber x (&quot;3154681.124&quot;);
  BigNumber y = x / BigNumber (&quot;100000&quot;);
  
  Serial.println(y);
  }  // end of setup

void loop ()
  {
  }  // end of loop
</code></pre>
<p>Output:</p>
<pre><code>31.5468112
</code></pre>
 4143: <pre><code>float x = 3154681.124 / 100000; //x = 31.54;
</code></pre>
<p><code>x</code> is now <code>31.5468112</code> (or close to).</p>
<pre><code>Serial.println(x);
</code></pre>
<p>Output: <code>31.54</code></p>
<p>Why? Because <code>Serial.println</code> defaults to 2 decimal places for floats.</p>
<blockquote>
<p>Syntax</p>
<p><code>Serial.println(val)</code></p>
<p><code>Serial.println(val, format)</code></p>
<p>Parameters</p>
<p><code>val</code>: the value to print - any data type</p>
<p><code>format</code>: specifies the number base (for integral data types) <strong>or number of decimal places (for floating point types)</strong></p>
</blockquote>
<p>So the solution: specift 7 decimal places when you print:</p>
<pre><code>Serial.println(x, 7);
</code></pre>
