title: STM32 floating point number calculation error
body: <p>I have to perform a calculation with 2 floating point numbers using measurements taken from a distance sensor with STM32. Calculation is carried out by following equation;</p>
  
  <blockquote>
    <p>result = (df-ds)/ds*10000; </p>
  </blockquote>
  
  <p>where df is first measurement and ds is second measurement.</p>
  
  <p>Sample values for equation;</p>
  
  <blockquote>
    <p>df = 26.6810;
    ds = 25.3270; </p>
  </blockquote>
  
  <p>My problem is, STM32's result for these values is <strong>534.578247</strong>, but when i do calculation on Windows' calculator manually i get the result of <strong>534.607336</strong> which is quite different from STM32's calculation. I've also used one hand-calculator and hand-calculator is giving out exactly same result with the computer.</p>
  
  <p>All variables are declared as floats in the program.
  Why is there so much difference between two calculations?
  What kind of changes i could make to make STM32 give more precise results?</p>
  
  <p>Thanks in advance for any help.</p>
  
  <p><strong>EDIT :</strong> The code i am using as follows;</p>
  
  <pre><code> float result= 0;
   dmbres = 27.4587;
     int main()
     {
     while(1)
     {
     result= (float)((dmbres- res)/res)*10000;
     dmbres = res;
     sprintf(datapackage, "%d;%.4f;%.6f\r\n", mid, res,result);
     monitor(datapackage);
     }
  </code></pre>
  
  <p><strong>datapackage</strong> consists 2 other information i need from MCU and they are not relevant with the <strong>result</strong> calculation. </p>
  
  <p>I am using STM32F407 DISC-1 board.</p>