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

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

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

/*
 *  System Versioning Preprocessor Macros hovertree.com
 */
#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")){...}

相关文章:

  • 2021-11-28
  • 2021-11-30
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
  • 2021-11-12
猜你喜欢
  • 2021-06-18
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案