title: Objective-C: Float addition error when returning to view
body: <p>I've got an NSDictionary made up of titles and floats (although they're stored as strings, for what it's worth), along the lines of "Paid for Dinner":"15.00".  Right now, those entries are <code>(15, 25.25, 25.75, 15)</code>, which should add up to <code>81</code>.  (And I've checked in the debugger, those are the correct values being stored, so it isn't a data source problem.)</p>
  
  <p>I want to get the sum of all the entries programmatically, so I've got a fairly simple bit of code to do that:</p>
  
  <pre><code>float currentTotal;
  for(id key in thisSet) {
      currentTotal = currentTotal + [[thisSet objectForKey:key] floatValue];
  }
  </code></pre>
  
  <p>By the end of the function, <code>currentTotal</code> is correctly set at <code>81</code>.</p>
  
  <p>Thing is, when I leave that ViewController and then return back to it, (by going from the MasterView, where I was, to the DetailView and then back, if it matters), the same function with the same values will return <code>81.006</code>.</p>
  
  <p>The values didn't change (I checked the debugger again, it's still precisely <code>(15, 25.25, 25.75, 15)</code>) and the code didn't change, so why would simply moving from to another View and back change the result?</p>
  
  <p><strong>NOTE:</strong> I know about floating point addition errors and such from other answers like <a href="https://stackoverflow.com/questions/13955329/objective-c-floating-point-addition-error">this</a> and <a href="https://stackoverflow.com/questions/1193554/trouble-with-floats-in-objective-c">this</a>.  I'm not looking for why floating point operations can be imprecise, I'm wondering why a change in View would affect the results.</p>