利用Math.Round(d0,0)方法四捨五入
與利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
double d0 = 1.4;
double d1 = 1.5;
double d2 = 1.6;
double d3 = 2.4;
double d4 = 2.5;
double d5 = 2.6;
Response.Write(d0.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d0, 0) + "<br/>");
Response.Write(d1.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d1, 0) + "<br/>");
Response.Write(d2.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d2, 0) + "<br/>");
Response.Write(d3.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d3, 0) + "<br/>");
Response.Write(d4.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d4, 0) + "<br/>");
Response.Write(d5.ToString() + "==利用Math.Round(d0,0)方法四捨五入後" + Math.Round(d5, 0) + "<br/>");
Response.Write(d0.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d0, MidpointRounding.AwayFromZero) + "<br/>");
Response.Write(d1.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d1, MidpointRounding.AwayFromZero) + "<br/>");
Response.Write(d2.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d2, MidpointRounding.AwayFromZero) + "<br/>");
Response.Write(d3.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d3, MidpointRounding.AwayFromZero) + "<br/>");
Response.Write(d4.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d4, MidpointRounding.AwayFromZero) + "<br/>");
Response.Write(d5.ToString() + "==利用Math.Round(d0, MidpointRounding.AwayFromZero)方法四捨五入後" + Math.Round(d5, MidpointRounding.AwayFromZero) + "<br/>");
}
}
執行結果
