.net扩展方法——对小数进行取位,默认保留2个小数点

.net扩展方法——对小数进行取位,默认保留2个小数点

 

        #region 对小数进行取位

        /// <summary>
        /// 对小数进行取位,默认保留2个小数点
        /// </summary>
        /// <param name="dcmal"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static decimal Round(this decimal dcmal, int point = 2)
        {
            return Math.Round(dcmal, point);
        }

        /// <summary>
        /// 对小数进行取位,默认保留2个小数点
        /// </summary>
        /// <param name="dcmal"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static decimal Round(this decimal? dcmal, int point = 2)
        {
            return Math.Round(dcmal ?? 0, point);
        }

        /// <summary>
        /// 对小数进行取位,默认保留2个小数点
        /// </summary>
        /// <param name="dcmal"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static double Round(this double dcmal, int point = 2)
        {
            return Math.Round(dcmal, point);
        }

        #endregion 对小数进行取位

 

posted @ 2020-08-13 13:53  小确幸123  阅读(641)  评论(0编辑  收藏  举报