asp.net数据四舍五入
程序员文章站
2022-05-01 18:25:33
#region 数据四舍五入
///
/// 四舍五入
///
///
#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
下一篇: 利用Android实现电子邮箱客户端