SQL 保留兩位小數的各類方法 git
1.求和後,保留兩位ide
sum(cast(cc.OrderDateCount as decimal(10, 2)))函數
2.平均值,保留小數this
CONVERT(decimal(10,2),avg(case when cc.ReceiveDateSum=0 then cc.ReceiveDateCount else
cc.ReceiveDateCount/cc.ReceiveDateSum end))spa
C# 保留兩位小數的各類方法 orm
1.用NumberFormatInfo類來解決:ci
System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();get
provider.NumberDecimalDigits =intDecLength; //要設定的小數位數數學
double strCashAmt=Convert.ToDouble(this.txtCashAmt.Text); //先把控件內的值轉成doublestring
this.txtCashAmt.Text = strCashAmt.ToString("N",provider); //再利用ToString函數格式化小數位數
二、用toString方法.:
public string getRate(double hcount, double task)
{
string rValue;
string temp = "";
if (task == 0)
{
task = 1;
}
double db = (hcount / task) * 100;
if (hcount >= task)
{
rValue = "100%";
}
else
{
rValue = db.ToString("#0.#0") + "%";
}
return rValue;
}
string str1 = String.Format("{0:N1}",56789); //result: 56,789.0 ({0:N1}金額一位小數)
string str2 = String.Format("{0:N2}",56789); //result: 56,789.00({0:N2}金額兩位小數)
string str3 = String.Format ("{0:N3}",56789); //result: 56,789.000 ({0:N3}金額三位小數)
string str8 = String.Format("{0:F1}",56789); //result: 56789.0 ({0:F1}一位小數)
string str9 = String.Format("{0:F2}",56789); //result: 56789.00({0:F2}兩位小數)
string str11 =(56789 / 100.0).ToString("#.##"); //result: 567.89 (除以小數)
string str12 =(56789 / 100).ToString("#.##"); //result: 56 (除以整數)
3.保留N位四捨五入
Math.Round(0.55555,2) //數學函數方法
4,保留N位四捨五入
double dbdata = 0.55555; string str1 = dbdata.ToString("f2");//fN 保留N位,四捨五入
5.保留N位四捨五入
string result = String.Format("{0:N2}", 0.55555);//2位
string result = String.Format("{0:N3}", 0.55555);//3位
6. 保留N位四捨五入
double s=0.55555;
result=s.ToString("#0.00");//點後面幾個0就保留幾位