Example #1
0
        /// <summary>
        /// 带2位小数
        /// </summary>
        /// <param name="number"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public static string ToNumberRoundStringWithPoint(this decimal number, int position = 2)
        {
            number = Math.Round(number, position, MidpointRounding.AwayFromZero);
            var intValue = number.As(0);

            return(number.ToString("#,##0.00"));
        }
Example #2
0
        /// <summary>
        /// 带小数则输出小数,否则输出整数
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static string ToNumberStringIntelligent(this decimal number)
        {
            var intValue = number.As(0);

            bool isInt = (number - intValue) == 0M;

            return(number.ToString(!isInt ? "#,##0.00" : "#,##0"));
        }
Example #3
0
        public static string ToCeilingNumberStringIntelligent(this decimal number)
        {
            number = Math.Ceiling(number * 100) / 100M;//2位进位
            var intValue = number.As(0);

            bool isInt = (number - intValue) == 0M;

            return(number.ToString(!isInt ? "#,##0.00" : "#,##0"));
        }
Example #4
0
        public static string ToNumberRoundString(this decimal number, int position = 2)
        {
            number = Math.Round(number, position);
            var intValue = number.As(0);

            bool isInt = (number - intValue) == 0M;

            return(number.ToString(!isInt ? "#,##0.00" : "#,##0"));
        }
Example #5
0
        public static string ToNumberStringNoZero(this decimal number)
        {
            var intValue = number.As(0);

            bool   isInt     = (number - intValue) == 0M;
            string returnStr = number.ToString(!isInt ? "#,##0.00" : "#,##0");

            if (returnStr.EndsWith("0"))
            {
                string returnStrOne = number.ToString(!isInt ? "#,##0.0" : "#,##0");
                return(returnStrOne);
            }
            return(returnStr);
        }
Example #6
0
        public static string ToNumberStringFloat(this decimal number)
        {
            var intValue = number.As(0);

            bool isInt = (number - intValue) == 0M;

            string str = string.Empty;

            if (isInt)
            {
                str = number.ToString("###0");
            }
            else
            {
                str = number.ToString("0.##");
            }
            return(str);
        }
Example #7
0
 /// <summary>
 /// Calculates the integral part of a specified double-precision floating-point number.
 /// </summary>
 /// <param name="d">The value to truncate.</param>
 /// <returns>The result.</returns>
 public static decimal Truncate(decimal d)
 {
     return(d.As <JsNumber>() | 0);
 }
Example #8
0
 public static decimal Round(decimal d, MidpointRounding mode)
 {
     return(Round(d.As <double>(), mode).As <decimal>());
 }
Example #9
0
 public int CompareTo(decimal other)
 {
     return(this.As <Number>().CompareTo(other.As <Number>()));
 }
Example #10
0
        public static decimal Round(decimal d, int decimals)
        {
            var pow = JsMath.pow(10, decimals);

            return(JsMath.round(d.As <JsNumber>() * pow.As <JsNumber>()) / pow);
        }