asp.net数据四舍五入

    #region 数据四舍五入
    /// <summary>
    /// 四舍五入
    /// </summary>
    /// <param name="dblnum">源数据</param>
    /// <param name="numberprecision">小数位</param>
    /// <returns></returns>
    private double GetRound(object objnum, int numberprecision)
    {
        double returnnum = 0;
        if (objnum != null)
        {
            try
            {
                double dblnum = double.Parse(objnum.ToString());
                int tmpNum = dblnum > 0 ? 5 : -5;
                double dblreturn = Math.Truncate(dblnum * Math.Pow(10, numberprecision + 1)) + tmpNum;
                dblreturn = Math.Truncate(dblreturn / 10) / Math.Pow(10, numberprecision);
                returnnum = dblreturn;
            }
            catch { }
        }
        return returnnum;
    }
    #endregion

posted @ 2013-09-13 09:46  深南大道  阅读(850)  评论(0编辑  收藏  举报