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 (15, 25.25, 25.75, 15)
, which should add up to 81
. (And I've checked in the debugger, those are the correct values being stored, so it isn't a data source problem.)
I want to get the sum of all the entries programmatically, so I've got a fairly simple bit of code to do that:
float currentTotal;
for(id key in thisSet) {
currentTotal = currentTotal + [[thisSet objectForKey:key] floatValue];
}
By the end of the function, currentTotal
is correctly set at 81
.
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 81.006
.
The values didn't change (I checked the debugger again, it's still precisely (15, 25.25, 25.75, 15)
) and the code didn't change, so why would simply moving from to another View and back change the result?
NOTE: I know about floating point addition errors and such from other answers like this and this. I'm not looking for why floating point operations can be imprecise, I'm wondering why a change in View would affect the results.