title: iOS - Operations with double values
body: <p>The APP I'm writting must do some financial calculations, basically it's all about credits, debits and the balance. The only problem (so far) is that if I calculate 999999999.99 - 0.00 the result is 1000000000.00. Please, does anyone know why that happens? Here's my code:</p>
  
  <pre><code>NSNumber *totalCredits;
  NSNumber *totalDebits;
  NSNumber *balance;
  
  self.credits = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
  totalCredits = [self.credits valueForKeyPath:@"@sum.amount"];
  double totalCreditsDouble = [totalCredits doubleValue];
  self.creditLabel.text = [NSString stringWithFormat:@"%1.2f", totalCreditsDouble];
  
  self.debits = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
  totalDebits = [self.debits valueForKeyPath:@"@sum.amount"];
  double totalDebitsDouble = [totalDebits doubleValue];
  self.debitLabel.text = [NSString stringWithFormat:@"%1.2f", totalDebitsDouble];
  
  balance = [NSNumber numberWithFloat:([totalCredits floatValue] - [totalDebits floatValue])];
  double balanceDouble = [balance doubleValue];
  self.balanceLabel.text = [NSString stringWithFormat:@"%1.2f", balanceDouble];
  </code></pre>
  
  <p>All the data is stored as Double.</p>