I wrote a sample to convert string to float in Objective-C:
NSString *sampleFloatString = @"1.3";
float sampleFloatValue = [sampleFloatString floatValue];
But when I display sampleFloatValue
, it shows '1.29999995'. I know it's equal to 1.3, but why is it not exactly '1.3'? Why do we need to format it explicitly? Is there any other way of doing this conversion?