objective-c - 将 NSInteger 转换为 float ,反之亦然

标签 objective-c ios ios5 nsinteger

我有基本的疑问。我必须转换 float minutes =( (10.09/60 ) % 60); 但错误是 invalid to binary expression(double to double)。 我怎样才能使这个计算简单.. 我首先要尝试的是 float =( (10.09/60) 然后尝试将分钟转换为 NSInterger 以解决模块 (%) 操作..

但是我该怎么做...或者建议其他解决方案来进行此计算..

float =( (10.09/60 ) % 60);

最佳答案

% 运算符不适用于浮点值。你必须使用一个函数来计算你想要的东西。这是它看起来像的基本伪代码:

B % A = B - (floor(B/A) * A)

还有一些库函数可以在 math.h 或 tgmath.h 中为您完成此操作

此外,您还可以使用: 来自 .

的 fmod() 或 fmodf()

关于objective-c - 将 NSInteger 转换为 float ,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971777/

相关文章:

iOS - 通过 Cydia Impactor 安装自签名的第三方应用程序的安全问题

iphone - NSPersistentStoreCoordinator 崩溃

objective-c - 设置 AVPlayerLayer VideoGravity 适用于模拟器,不适用于 iPad

ios - objective-c 中一次有多个异步请求

iphone - 核心数据,validateForInsert :/validateForUpdate: create an entity even when they cancel

ios - 图片库在 UIScrollview 可见之前闪烁黑屏

ios - 在 Swift 中解析关系

iphone - CoreBluetooth 可以使用什么配置文件?

ios - 如何让我的 iPhone 启动图像使用用户的状态栏?

ios - AV播放器 "Cannot Complete Action"