C#:数学运算(待补充)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyCommanHelper
{
    public class MathHelper
    {

    #region 舍入值

        /// <summary>
        /// 将值舍入为绝对值较小的那个
        /// </summary>
        /// <param name="s"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static double Round(double s, int n)
        {
            return (double)decimal.Round((decimal)s, n, MidpointRounding.AwayFromZero);
        }

        public static double Round(string ss, int n)
        {
            return Round(ConvertHelper.ObjectToDouble(ss), n);
        }

        public static double Round(object obj, int n)
        {
            return Round(ConvertHelper.ObjectToDouble(obj), n);
        }

        /// <summary>
        /// 将值舍为最接近的偶数
        /// </summary>
        /// <param name="s"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static double RoundToEven(double s, int n )
        {
            return (double)decimal.Round((decimal)s, n, MidpointRounding.ToEven);
        }

        public static double RoundToEven(string ss, int n)
        {
            return RoundToEven(ConvertHelper.ObjectToDouble(ss), n);
        }

        public static double RoundToEven(object obj, int n)
        {
            return RoundToEven(ConvertHelper.ObjectToDouble(obj), n);
        }
    #endregion

    }
}
原文地址:https://www.cnblogs.com/shenchao/p/3673383.html