开发者

Math.Round Variable? Visual basic

开发者 https://www.devze.com 2023-02-16 21:46 出处:网络
I\'m writing a program for my visual basic class that computes the prices of cans per pound. I have the program running, but I need to round the cents up to the nearest dollar. How can I do this in vb

I'm writing a program for my visual basic class that computes the prices of cans per pound. I have the program running, but I need to round the cents up to the nearest dollar. How can I do this in vb? Is it possible to round a decimal variable?

I'm sorry if this sounds stupid, I am a newb lol.

Here is my code.

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


You can use the function: Math.Round(value)

0

精彩评论

暂无评论...
验证码 换一张
取 消