我的情况是,如果如果它有小数点位置,则将值增加1?
47/15= 3.13333
我想把它转换成4,如果结果有小数,我想通过1增加的结果,现在我这样做像
float res = ((float)(62-15)/15);
if (res.ToString().Contains("."))
{
string digit=res.ToString().Substring(0, res.ToString().IndexOf('.'));
int incrementDigit=Convert.ToInt16(k) + 1;
}
我想知道是否有任何快捷方式或在C#中的函数内置,以便我可以做到这一点,而不需要实现字符串函数。
非常感谢。
Math.Ceiling ?: http://msdn.microsoft.com/en-us/library/vstudio/zx4t0t48.aspx – Fox32 2013-05-10 12:20:51
http://stackoverflow.com/questions/904910/how-do-i-round- a-float-up-the-the-int-in-c – Steve 2013-05-10 12:21:13
你的意思是像'System.Math.Ceiling'这样的东西是四舍五入吗? (子问题:如果你的数字是负数,“-3.13333”应该仍然“添加”一个,并使-4或_really_添加并使其为-3?) – 2013-05-10 12:21:19