Convert a string to float in Objective C without rounding it.?
ios, iphone, objective-c, string
Solution
The problem is you're using a float. A float can usually only hold around 7-digits max. A double can hold many more digits. A float is 32-bit while a double is 64-bit therefore giving it "double" the precision. A simple work-around to your problem would be to do:
`double result = [string doubleValue];`
When logging, make sure to use `NSLog(@"%.12f",result);` to show the entire double as %f defaults to only a 6 decimal precision.
Problem
How can i convert a string to float in Objective C without rounding it.? I tried to convert a string 8.56021285234; ``` float result=[string floatValue]; ``` giving 8.560213, the rounded value. How can i avoid this? How i can get the exact value?