美文网首页
C#向上、向下、四舍五入取整

C#向上、向下、四舍五入取整

作者: 左岸花未开 | 来源:发表于2019-05-31 18:46 被阅读0次

    Math.Ceiling()向上取整,Math.Floor()向下取整 ,Math.Round()四舍五入取整
    示例:
    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

    相关文章

      网友评论

          本文标题:C#向上、向下、四舍五入取整

          本文链接:https://www.haomeiwen.com/subject/zcngtctx.html