【发布时间】:2013-04-03 15:16:33
【问题描述】:
不好意思问这个,但我运行的是 iOS 6.1,下面这行返回 False:
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.1)
但以下返回 True:
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.1f)
为什么?
【问题讨论】:
-
双精度浮点比单精度浮点更精确,因此值可能不同。 可能有重复,看这里:stackoverflow.com/questions/15581535/…
-
在使用 iOS 系统版本时,我检索了完整的字符串(例如,6.1.3,我将其拆分为由 '.' 分隔的部分,然后从值创建一个 NSIndexPath,然后您可以进行比较您的系统版本使用另一个 NSIndexPath 并且不受实数精度问题的影响。抱歉,我现在没有代码,但您应该能够复制我刚才告诉您的方法
标签: ios objective-c