小数点四舍五入

        /// <summary>
        /// 截取小数点位数(四舍五入)
        /// </summary>
        /// <param name="v"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        public static decimal subRound(decimal v, int x)
        {
            int IValue = 1;
            for (int i = 1; i <= x; i++)
            {
                IValue = IValue * 10;
            }

            v = v * IValue;
            decimal Int = v - (int)v;
            if (Int >= (decimal)0.5)
                v += 1;
            v = (decimal)((int)v) / IValue;
            return v;
        }

 

posted @ 2015-09-20 21:51  凌晨10点13分  阅读(167)  评论(0编辑  收藏  举报