如何在iPhone应用程序中将浮点值转换为四舍五入 [英] how to convert a float value to rounded off in iphone app

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

问题描述

我有一个浮点值,我想四舍五入到最接近的总数,我找到了一些数学函数,但是不起作用

I have a float value i want to rounded off to nearest total i have find some math function but not working

现在潜在的利润是300.52,所以如何四舍五入

Now potential profit is 300.52 so how to roundded of this please

     float potentialprofit=otherthanCereniaAnnual*totalProfit;
     NSString*potentialProfitTitle=[NSString stringWithFormat:@"%.2f",potentialprofit];

[potentialProfit setTitle:potentialProfitTitle forState:UIControlStateNormal];

推荐答案

int result = (int)ceilf(myFloat );
int result = (int)roundf(myFloat );
int result = (int)floor(myFloat);

float result = ceilf(myFloat );
float result = roundf(myFloat );
float result = floor(myFloat);

我认为这将对您有所帮助.

I think it will be helpful to you.

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

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