Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
float beat = 1/2; NSLog(@"timeinterval: %f",beat);
"timeinterval" 一直为 0
我的xcode有问题吗?还是我只是在这里坐得太久而错过了一些明显的东西?
这是 C 中整数除法的结果(这是 objc 的基础)。要解决此问题,请显式使用浮点值:
float beat = 1.0 / 2.0; NSLog(@"%f", beat); // works correctly.
float x = 1.0/2.0; NSLog(@"The Float Number is %f",x);
这就是你将如何计算x浮点数的值。
x