I have an array in which the input to textfield.text is stored. Then I extract the text elsewhere as a float. This seems to give me the “exact number” in the text box.
Example A
navtestAppDelegate *appDelegate = (navtestAppDelegate *)[[UIApplication sharedApplication] delegate]; NSMutableArray *storedData = appDelegate.myData; [storedData replaceObjectAtIndex: myIndex withObject: mytextfield.text]; float number = [[storedData objectAtIndex:myIndex] floatValue];
the if mytextfield.text input is 22.8, float numberreturns22.8
mytextfield.text input is 22.8
float number
22.8
but,
Example B
[storedData replaceObjectAtIndex: myIndex withObject: @"22.8"]; float number = [[storedData objectAtIndex:myIndex] floatValue];
float number returns 22.7999999
22.7999999
I do not understand why I get the exact number in example A
22.8 . , , , . . , 22.8 22.7999999 , . , 22.7999999, 22.8000000, 2, .
, , , , . 22.8 .
, NSDecimal , .
pi , , - , . , pi ( ) pi.: -)
float double , .
float
double
: -
[storedData replaceObjectAtIndex: myIndex withObject: [NSNumber numberWithFloat:22.8]];