开发者

problem when get floatValue from NSString

I am confusing and don't know why it's happen that when I get float from string.

I have an array of NSString, and when I get floatValue from these string object, they are not correct, for an example:

NSString object is "71.4" => floatValue is 71.4000013

NSStrin开发者_如何学编程g obtect is "71.45"=> floatValue is 71.4489839

Does anyone know the root cause and how to resolve, please help me!

Thanks!


Welcome to the joys of floating point. These ARE 'correct'. Floating point values are very inaccurate due to how they're stored on the system.

Here is a much better explanation than I'll be able to give.


Try doubleValue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜