如何在Objective C中将float转换为int? [英] How do I convert a float to an int in Objective C?

查看:116
本文介绍了如何在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.

这篇关于如何在Objective C中将float转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆