zoukankan      html  css  js  c++  java
  • 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
    
        }
    }
    
  • 相关阅读:
    [atARC100F]Colorful Sequences
    [atARC103D]Robot Arms
    [atARC107F]Sum of Abs
    [atAGC047F]Rooks
    [loj3278]收获
    [cf809E]Surprise me
    [cf997E]Good Subsegments
    [cf603E]Pastoral Oddities
    Codeforces Round #453
    Educational Codeforces Round 32
  • 原文地址:https://www.cnblogs.com/shenchao/p/3673383.html
Copyright © 2011-2022 走看看