converting to currecny and decimal

Hekzdaddy 121 Reputation points
2021-03-14T22:35:29.61+00:00
    decTotalCost = intNumDays * decLocationFee + decRegistrationFee
    lstCost.Items.Add(decTotalCost).ToString("c")

in the statement above, the right amount is sent to lstCost, but not as a ("c") or a decimal, any suggestions?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,662 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,386 Reputation points
    2021-03-15T12:34:09.037+00:00

    Is this what you want? Note how I've done the format without ToString.

    private void button1_Click(object sender, EventArgs e)  
    {  
        int intNumDays = 8;  
        decimal decLocationFee = 23.77m;  
        decimal decRegistrationFee = 12.99m;  
          
        decimal decTotalCost = intNumDays * decLocationFee + decRegistrationFee;  
        lstCost.Items.Add($"{decTotalCost:C}");  
    }  
    

    77788-f2.png


1 additional answer

Sort by: Most helpful
  1. Jack J Jun 24,496 Reputation points Microsoft Vendor
    2021-03-15T06:34:33.84+00:00

    Hi @Hekzdaddy ,

    the right amount is sent to lstCost, but not as a ("c") or a decimal,

    Change :
    lstCost.Items.Add(decTotalCost).ToString("c")
    To:
    lstCost.Items.Add(decTotalCost.ToString("c"))

    Best Regards,
    Jack

    1 person found this answer helpful.
    0 comments No comments