zoukankan      html  css  js  c++  java
  • iOS版本比较的精确方法

    来源于stackoverflow.

    之前一直把版本号转换为floatValue,但是最近在项目中又出现了float的问题,主要是

    NSString表示为@"17.30",转换为floatValue 值为17.299999,然后做了一些放大处理,导致不精确,就是精度少了1

    所以都不敢在系统版本比较的过程中把值强制转换为floatValue了。

    /*
     *  System Versioning Preprocessor Macros
     */
    #define SYSTEM_VERSION_EQUAL_TO(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]==NSOrderedSame)

    #define SYSTEM_VERSION_GREATER_THAN(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]==NSOrderedDescending)

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]!=NSOrderedAscending)

    #define SYSTEM_VERSION_LESS_THAN(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]==NSOrderedAscending)

    #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]!=NSOrderedDescending)

    /* * Usage */if(SYSTEM_VERSION_LESS_THAN(@"4.0")){...}

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")){...}
  • 相关阅读:
    Don‘t Cry for Me, Argentina
    对象池
    拒绝高姿态
    SOS: How to popup a HwndSource on topmost
    关于设计和设计文档的2个补充
    从今天开始写博客
    Kafka+Storm写入Hbase和HDFS
    工作流调度引擎Oozie
    showModalDialog在父窗体和子窗体之间传值
    慢说HttpContext
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2821559.html
Copyright © 2011-2022 走看看