Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Odd float value

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-OTHER, Mac OS X (10.7.4)

Posted on May 26, 2012 12:45 PM

Reply
Question marked as Best reply

Posted on May 26, 2012 1:10 PM

The Nickels and pennies are set to the quarters.txt, is that what you want?

2 replies

Odd float value

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.