且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-09-20 19:53:56

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


本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/p/5704193.html,如需转载请自行联系原作者