2014-04-01 35 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