I used this code to cut the string
NSString *titleString = @"22.225453615805794,113.554006577014889";
NSArray *array = [titleString componentsSeparatedByString:@","];
NSLog(@"title string %@", titleString);
NSLog(@"first %.15f", [[array objectAtIndex:0] floatValue]);
NSLog(@"second %.15f", [[array objectAtIndex:1] floatValue]);
but why it return
22.225454330444336 and 113.554008483886719
Because floating point numbers are not that accurate, you can get a higher accuracy by calling doubleValue
instead of floatValue
:
NSLog(@"second %.15f", [[array objectAtIndex:1] doubleValue]);
This is not a problem with componentsSeparatedByString:
.
I think there is problem in converting string into float. Try using double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With