Whenever the textfield contains 9 or more numbers, [textfield.text floatValue] will return a number with the first 7 numbers correct, but the last 2 wrong. For example, say I type 987654321 into the textfield. It will show in the actual textfield that I type 987654321. However, [textfield.text floatValue] will return something to the effect of 987654336. Why is this? Here is some code:
Code:
-(IBAction)numberOneKeyPressed {
//If the textfield isn't empty
if([textField.text length] != 0) {
//And if the textfield has less than 9 numbers
if([textField.text length] < 9) {
//Add a 1 to the end of the previous textfield value
textField.text = [NSString stringWithFormat:@"%.0f1",textFieldFloatValue];
//And assign the textfield floatvalue to the float variable
textFieldFloatValue = [[textField text] floatValue];
}
}
//if the textfield was empty to begin with
else {
//just make the textfield say 1
textField.text = [NSString stringWithFormat:@"1"];
//and assign the floatvalue to the float variable
textFieldFloatValue = [[textField text] floatValue];
}
//The NSLog here returns the incorrect value therefore showing me that the float variable is incorrect as well
NSLog(@"%.0f",[[textField text] floatValue]);
}
As you can see, I have created a custom keyboard dealing with numbers. The method I provided you with is what is called when the user press the 1 button on the custom keyboard. Of course, I have the methods for the other numbers as well, but they are pretty much duplicates of this method, but substituting the correct numbers depending on which key is pressed. It works completely fine until the 9th number. Any ideas as to what's going on? Thanks in advance.