Skip navigation

Odd float value

260 Views 2 Replies Latest reply: May 26, 2012 1:30 PM by iTryFreeApps RSS
iTryFreeApps Level 1 Level 1 (30 points)
Currently Being Moderated
May 26, 2012 12:45 PM

I have a little problem with my decimal values while I'm building an app on the iOS 5.1.1 SDK, and I don't know how to fix this. I have a meathod (I'm pretty sure it's declared in my header file under the right class), and this is the meathod:


-(IBAction)findAmount:(id)sender {
    int numOfQuarters = [quarters.text intValue];
     int numOfDimes =    [dimes.text intValue];
     int numOfNickels =  [quarters.text intValue];
     int numOfPennies =  [quarters.text intValue];
     NSNumber *amountText = [[NSNumber alloc]initWithFloat:(numOfQuarters * 0.5) + (numOfDimes * 0.1) + (numOfNickels * 0.05) + (numOfPennies * 0.01)];
     NSLog(@"%@", amountText);
}

 

The problem is, every time I tap the sender, which is a UIButton object, the console says 1.68, but I'm setting the variable numOfQuarters to three, and every other variable in the arithmetic problem to zero when I run it.

Please tell me how to fix this, because I'm going crazy...

Xcode 4, Mac OS X (10.7.4)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.