Adding checkboxes and displaying as currency ("c")

Hekzdaddy 121 Reputation points

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

    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