在C#中使用Math.Ceiliing时出错 [英] Error using Math.Ceiliing In C#

查看:164
本文介绍了在C#中使用Math.Ceiliing时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我收到的错误就像以下方法或属性之间的调用不明确:'System.Math.Ceiling(double)'和'System.Math.Ceiling(decimal) '



int pages_used = Convert.ToInt32(Math.Floor(Convert.ToDouble(Math.Ceiling(tblAuthors1.Rows.Count / 4))));

Hi All,
I am getting error Like The call is ambiguous between the following methods or properties: 'System.Math.Ceiling(double)' and 'System.Math.Ceiling(decimal)'

int pages_used = Convert.ToInt32(Math.Floor(Convert.ToDouble(Math.Ceiling(tblAuthors1.Rows.Count/4))));

推荐答案

使用 4.0 代替 4 解决歧义:
Convert.ToInt32(Math.Floor(Convert.ToDouble(Math.Ceiling(tblAuthors1.Rows.Count/4.0))));





[更新]

请注意:正如 Matt T Heffron 正确指出的那样,上面一行包含了很多内容不必要的东西。你可以(而且应该)简单地写:



[update]
PLEASE NOTE: As correctly pointed out by Matt T Heffron the above line contains a lot of unnecessary stuff. You could (and should) simply write:

int pages_used = (int)Math.Ceiling(tblAuthors1.Rows.Count/4.0);



[/ update]





或只是写:


[/update]


or simply write:

int count = tblAuthors1.Rows.Count;
int pages_used = count/4 + (count % 4 > 0 ) ? 1 : 0;


你可以使用



int pages_used = Convert.ToInt32(Math.Floor(Math.Ceiling((Convert.ToDouble(tblAuthors1.Rows.Count))/ 4)) );



希望这有助于
You can use

int pages_used = Convert.ToInt32(Math.Floor(Math.Ceiling((Convert.ToDouble( tblAuthors1.Rows.Count)) / 4)));

Hope this helps


上限方法可以将值四舍五入到接近给定值的最高值....所以只有

System.Math.Ceiling正常工作....
the ceiling method can round the value to highest close to given value.... so only the
System.Math.Ceiling work properly....


这篇关于在C#中使用Math.Ceiliing时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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