2014-04-01 32 views
0
If RadioButtonAC144.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/144 
    ElseIf RadioButtonAC72.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/72 
    ElseIf RadioButtonAC48.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/48 
    ElseIf RadioButtonAC35.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/35 
    ElseIf RadioButtonAC32.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/32 
    ElseIf RadioButtonAC24.Checked = True Then 
     TextBoxACScale.Text = TextBoxACReal.Text/24 
    End If 

這是我的代碼,我有多個頁面(標籤)與此類似,所以這是一個PITA改變了這一切,但如果它是唯一的辦法那就這樣吧,但是我只是需要在TextBoxACScale.Text中顯示的結果最多隻顯示2位小數。單擊計算按鈕時將實現此代碼。2位小數結果在VB

+0

http://stackoverflow.com/questions/5168592/force-a-string-to-2-decimal-places VB.net和C#是相同的。使用String.Format –

+0

你不能用整數分割文本。你必須將文本轉換爲數字,進行分割,然後轉換回來。 – ja72

+0

現在一切正常。我改變了剩下的部分。作爲領導與文本的分工,這樣的工作很好。 – Michael

回答

2
Dim Divisor As Integer = 1 
If RadioButtonAC144.Checked Then 
    Divisor = 144 
ElseIf RadioButtonAC72.Checked Then 
    Divisor = 72 
ElseIf RadioButtonAC48.Checked Then 
    Divisor = 48 
ElseIf RadioButtonAC35.Checked Then 
    Divisor = 35 
ElseIf RadioButtonAC32.Checked Then 
    Divisor = 32 
ElseIf RadioButtonAC24.Checked Then 
    Divisor = 24 
End If 
TextBoxACScale.Text = (Convert.ToDecimal(TextBoxACReal.Text)/Divisor).ToString("F2") 
+0

用於使用To String格式:F2 – Codexer

0
If RadioButtonAC144.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/144,2) 
ElseIf RadioButtonAC72.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/72,2) 
ElseIf RadioButtonAC48.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/48,2) 
ElseIf RadioButtonAC35.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/35,2) 
ElseIf RadioButtonAC32.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/32,2) 
ElseIf RadioButtonAC24.Checked = True Then 
    TextBoxACScale.Text = Round(TextBoxACReal.Text/24,2) 
End If