asp.Netデータ四捨五入

1038 ワード

    #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