在Switch语句中使用Double
下面所有的值都是双精度的,但是开关需要一个整数值。 有没有办法解决?
switch(fivePercentValue){ case floor((5*fivePercentValue) / 100): fivePercent_.backgroundColor = [UIColor greenColor]; fivePercentLabel_.textColor = [UIColor greenColor]; break; case ceil((5*fivePercentValue) / 100): fivePercent_.backgroundColor = [UIColor greenColor]; fivePercentLabel_.textColor = [UIColor greenColor]; break; default: fivePercent_.backgroundColor = [UIColor redColor]; fivePercentLabel_.textColor = [UIColor redColor]; break;
你可能会更好地使用if else和testing范围,但你可以在你的fivePercentValue上执行一些math,然后将其转换为一个整数,以便不同的整数代表不同的范围,例如
switch( (int)(value*10.0) ) { case 0: // this is 0.0 <= value < 0.1 break; case 1: // this is 0.1 <= value < 0.2 break; case 2: // this is 0.2 <= value < 0.3 break; .... }
- animationMKOverlayView
- 在swift编程中没有理解初始化的过程
- 使用Transporter从Linux处理iOS App元数据
- 永远不要在Apple statusUpdateNotification上获得更新通知类型
- 渲染一个SCNGeometry作为一个线框
- ARKit + SceneKit几何图形教程(第1部分)
- 点击或滚动后,asynchronous下载的图像只出现在UITableView中
- 在UIImageView中加载animation的图像 – iOS
- 不能分配types的值(string!,Bool,!,NSError!) – >无效的值typesUIActivityViewControllerCompletionWithItemsHandler?