如何在Objective C中将float转换为int?
问题描述:
总新手问题,但这是驱动我疯了!
我试试这个:
Total newbie question but this is driving me mad! I'm trying this:
myInt = [myFloat integerValue];
但我得到一个错误,说明基本上integerValue不工作浮点。
but I get an error saying essentially integerValue doesn't work on floats.
我如何做?
答
肯定的C风格的转换语法在Objective C中工作,所以试试:
I'm pretty sure C-style casting syntax works in Objective C, so try that, too:
int myInt = (int) myFloat;
至少可能会隐藏编译器警告。
It might silence a compiler warning, at least.