2014-06-13 64 views
0

我需要從文本框中獲取數字,並在另一個文本框中將該數字除以5.5。答案需要四捨五入到最接近的整數。我遇到的問題是如何使用文本框來實現Math.Round?下面是我試圖讓它起作用。使用Math.Round與MidpointRounding.AwayFromZero圍繞數字

double num2 = Math.Round(Convert.ToDouble(textBox5.Text,1,0))/5.5; 
textBox6.Text = num2.ToString(); 

double num2 = Math.Round((Convert.ToDouble)textBox5.Text/5.5); 

double num2 = Math.Ceiling(Convert.ToDouble(textBox5.Text,0.00(MidpointRounding.AwayFromZero)))/5.5; 
textBox6.Text = num2.ToString(); 

回答

1

我想打破它每行代碼的單一操作,做這樣說:

var x = Double.Parse(textBox5.Text); 

x = x/5.5; 

x = Math.Round(x, MidpointRounding.AwayFromZero); 

textBox6.Text = x.ToString(); 
+0

美麗謝謝 –