如何在 iPhone SDK 中舍入浮点值并将其转换为 NSInteger 值? [英] How to round an float value and convert it into NSInteger value in the iPhone SDK?

查看:56
本文介绍了如何在 iPhone SDK 中舍入浮点值并将其转换为 NSInteger 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要舍入一个浮点值并将其转换为 NSInteger 值.

I need to round a float value and convert it into an NSInteger value.

例如:

float f = 90.909088;

我希望结果是 91.如何摆脱这个?

I want the result to be 91. How to get rid of this?

推荐答案

以下 C 数学函数之一可能适合您:

One of the following C math functions might work for you:

  • 双天花板(双)
  • 双层(双人)
  • double nearint(double)
  • double rint(double)
  • 双轮(双)
  • long int lint(double)
  • long int lround(double)
  • long long int llrint(double)
  • long long int llround(double)
  • 双截断(双)

要获取更多文档,请打开终端会话并输入(例如)

To get more documentation, open a terminal session and type (for example)

man lround

我选择 lround 作为示例,因为我认为那是您想要的.

I pick lround as an example because I think that is the one you want.

这篇关于如何在 iPhone SDK 中舍入浮点值并将其转换为 NSInteger 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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