I have two text fields in my view. After prompting the user to enter a value, I convert them to floats to do my calculations.
I use the following code:
variable1 = [textField1.text floatValue];
variable2 = [textField2.text floatValue];`
When the user enters 22.8 in textField1, I get 22.80005 in variable1.
I do not get the exact value!
How do I get the exact decimal value? Any addition could affect the accuracy of the calculations.
And another question hits SO about floating point accuracy!
You should use
NSDecimalNumberinstead:There’s some more info in the Number and Value Programming Guide.