ios - float value from [NSString floatValue] show different result when print out -
Please refer to the code below and view in the results console.
NSString * strRatio = @ "0.03"; Float F = [stratio float value]; NSLog (@ "% F,% @", F, F = 0.03? @ "Equal": @ "not equal"); Result:
0.030000, not equal In addition to this I have a screenshot when I NSLog (@ "% f,% @", f, f == 0.03? @ "Par": @ "not equal"); , it is showing me f 0.0299999993 ... Can anyone explain it?
- Why is the result of
f = 0.03 false? - Why F is 0.030000 but it shows 0.0299999993 when debug occurs.
edited Do:
I hope the value of f is 0.03 after converting from "0.03", how can I get it?
It seems that float 0.03 is represented by Even if I assign 0.03 to the float value, then I will get 0.029999993 as a result.
Value is not 0.03 , as is D As shown in the second - 0.0299999993 . It shows in the log as 0.03000 default, % f 5 Displays the decimal place, so the value is being rounded on 0.0299999993 to 0.03000 . Change the log % .10f And you'll see the actual value.
Comments
Post a Comment