question

Hekzdaddy-3952 avatar image
0 Votes"
Hekzdaddy-3952 asked Hekzdaddy-3952 commented

converting to currecny and decimal



     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?

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered Hekzdaddy-3952 commented

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



f2.png (2.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That looks like it worked, I will give it a shot, I dont think I've learned that method.

0 Votes 0 ·
JackJJun-MSFT avatar image
1 Vote"
JackJJun-MSFT answered

Hi @Hekzdaddy-3952 ,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.