c#中取整,向上取,向下取

   
Math.Ceiling()向上取整,Math.Floor()向下取整
示例:
d = 4.56789
string res = Math.Ceiling(Convert.ToDecimal(d)).ToString()
或string res = Math.Ceiling(Convert.ToDouble(d)).ToString();
res为5

string res = Math.Floor(Convert.ToDecimal(d)).ToString()
或string res = Math.Floor(Convert.ToDouble(d)).ToString();
res为4
posted on 2016-01-31 11:27  張暁磊  阅读(474)  评论(0编辑  收藏  举报