title: Extracting decimal part of a float accurately
body: <p><em>Note: I am coding the following in the Arduino variant of C++.</em></p>
  
  <p>From a given float (always with four decimal digits), I wish to extract just the decimal part ("mantissa") as an integer.</p>
  
  <p>So I attempted this method:</p>
  
  <pre><code>void ExtractDecimalPart(float Value) {
    int IntegerPart = (int)(Value);
    int DecimalPart = 10000 * (Value - IntegerPart); //10000 b/c my float values always have exactly 4 decimal places
    Serial.println (DecimalPart);
  }
  </code></pre>
  
  <p>But the above results in the following:</p>
  
  <pre><code>ExtractDecimalPart (1234.5677); //prints 5677
  ExtractDecimalPart (1234.5678); //prints 5677
  ExtractDecimalPart (1234.5679); //prints 5678
  </code></pre>
  
  <p>Note that the latter two print out wrong; I'm guessing this is due to floating point precision issues.</p>
  
  <p>What is an economical way to solve the above?</p>