- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我正在尝试制作一个简单的 Objective-C 高度转换器。输入是英尺的 (float) 变量,我想转换为 (int) 英尺和 (float) 英寸:
float totalHeight = 5.122222;
float myFeet = (int) totalHeight; //returns 5 feet
float myInches = (totalHeight % 12)*12; //should return 0.1222ft, which becomes 1.46in
但是,我不断收到来自 xcode 的错误,并且我意识到模运算符仅适用于 (int) 和 (long)。有人可以推荐一种替代方法吗?谢谢!
最佳答案
即使模数也适用于 float ,使用:
fmod()
你也可以用这种方式...
float totalHeight = 5.122222;
float myFeet = (int) totalHeight; //returns 5 feet
float myInches = fmodf(totalHeight, myFeet);
NSLog(@"%f",myInches);
关于iOS objective-C : using modulo on a float to get "inches" from Feet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16394216/
我想在 pylab 中绘制一个图,它在 y 轴上显示英尺,并将英尺分割为英寸而不是英尺的分数。这在公制系统中不是问题,因为单位分割与十进制系统一致,但使用英制单位时确实会使图表难以阅读。 这可能吗?
几年前,我读了一篇关于分析大型代码库的巧妙方法的文章。 这个想法是到目前为止缩小到缩进和块长度的模式都是真正可见的。 作者写了关于用非常小的字体打印代码并从 10 英尺后查看结果的文章。我相信作者也有
我正在尝试匹配英尺和英寸,但我无法设法得到“和/或”,所以如果前半部分是正确的,它会验证: 代码:(在 javascript 中) var pattern = "^(([0-9]{1,}\')?([0
我使用 D-Feet D-Bus 调试器来调查一些接口(interface)。 其中之一需要 variant类型作为参数发送(这意味着您可以发送任何内容)。 但我无法将参数发送为 variant -
我一直在使用 Measurement 对象从大部分长度进行转换。但我有一个奇怪的问题。如果我将英里转换为英尺,我几乎可以得到正确的答案。 import Foundation let heightFee
我正在尝试制作一个简单的 Objective-C 高度转换器。输入是英尺的 (float) 变量,我想转换为 (int) 英尺和 (float) 英寸: float totalHeight = 5.1
我是一名优秀的程序员,十分优秀!