0
我正在为我的Visual Basic类编写一个程序,计算每磅罐的价格。我的程序正在运行,但我需要将美分汇总到最接近的美元。我怎样才能在vb中做到这一点?是否可以舍入一个十进制变量?Math.Round变量? Visual basic
对不起,如果这听起来很愚蠢,我是一个新手大声笑。
这是我的代码。
Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Variables
Dim cans As Integer
Dim canPounds As Integer
Dim canPoundTotal As Decimal
Dim canWorth As Decimal = 0.75
Dim cansNeeded As Integer
'Conversions
cans = Convert.ToInt32(txtGoal.Text)
'Calculation
canPounds = cans/24
canPoundTotal = canPounds * canWorth
cansNeeded = 33000 - cans
If cboNeed.SelectedIndex = 0 Then
lblOutput.Text = cansNeeded.ToString + " cans need to be collected to reach your goal"
ElseIf cboNeed.SelectedIndex = 1 Then
lblOutput.Text = canPoundTotal.ToString("C") & " will be earned by collecting cans for recycling"
End If
End Sub
Private Sub cboNeed_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboNeed.SelectedIndexChanged
If cboNeed.SelectedIndex = 0 Then
lblDesc.Text = "Target Goal Amount"
btnCalculate.Text = "Find Target Amount of Cans"
ElseIf cboNeed.SelectedIndex = 1 Then
lblDesc.Text = "Cans Collected"
btnCalculate.Text = "Find Amount Earned"
End If
End Sub
End Class
所以如果结果是$ 99.75。 Math.Ceiling会把它凑到100美元? – 2011-03-16 03:37:45