我的情況是,如果如果它有小數點位置,則將值增加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