Display currency format upto two decimal place in Label using C# in ASP.Net

micah
 
on Oct 18, 2021 03:57 AM
491 Views

I have this currency written in code but i want to format it like below

decimal total = Convert.ToDecimal(dt.Compute("SUM(Total)", String.Empty));
Label8.Text = "Total is <b> : " + total.ToString() + "</b>";

format below

decimal total = Convert.ToDecimal(dt.Compute("Sum","N{0:N2}(Total)", String.Empty));
Label8.Text = "Total is <b> : " + total.ToString() + "</b>";

but i get error on Compute

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Oct 18, 2021 04:00 AM
on Oct 20, 2021 07:27 AM

Chenge with below code.

decimal total = Convert.ToDecimal(dt.Compute("SUM(Total)", String.Empty));
Label8.Text = "Total is <b> : " + total.ToString("N2") + "</b>";

Or

decimal total = Convert.ToDecimal(dt.Compute("SUM(Total)", String.Empty));
Label8.Text = "Total is <b> : " + String.Format("{0:N2}", total) + "</b>";

Output

Total is 100.25