Adding checkboxes and displaying as currency ("c")

Hekzdaddy 121 Reputation points
2021-02-25T20:41:22.51+00:00

So I have been using the code below and get the appropriate results for the first three IF statements. However, when trying to add the check bokes, I get a whole number, not a decimal and not a currency value. I am not sure on how to display the addition of text boxes as ("c"), any advise?

'Check for additional services
If chkLevel3.Checked = True Then
lblFeatures.Text = decchkLevel3.ToString("c")
End If
If chkOnSite.Checked Then
lblFeatures.Text = decchkOnSite.ToString("c")
End If
If chkCloud.Checked = True Then
lblFeatures.Text = decchkCloud.ToString("c")
End If

        If chkOnSite.Checked And chkCloud.Checked Then

            lblFeatures.Text = decchkOnSite + decchkCloud

        End If
        If chkOnSite.Checked And chkLevel3.Checked Then

            lblFeatures.Text = decchkOnSite + decchkLevel3
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,783 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114K Reputation points
    2021-02-25T21:47:11.293+00:00

    If you want to display the sum, then try lblFeatures.Text = (decchkOnSite + decchkCloud).ToString("C").

    The whole code can be probably improved or simplified, maybe like this:

    lblFeatures.Text = (If(chkLevel3.Checked, decchkLevel3, 0) + If(chkOnSite.Checked, decchkOnSite, 0) + If(chkCloud.Checked, decchkCloud, 0)).ToString("C")
    

0 additional answers

Sort by: Most helpful