Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using This Calculation.I want to get Total in two decimal point in my Label.This code answers without decimal point. how to solve this Problem.anyone can help me.
C#
//get sum of value

    Decimal summ = 0;
    for (int n = 0; n < Cusinvoicegrid0.Rows.Count; ++n)
            {
                 summ += Convert.ToDecimal(Cusinvoicegrid0.Rows[n].Cells[3].Text);
            }
                       

          Decimal tott = Math.Round(summ,2);
          Label3.Text = tott.ToString();
Posted
Updated 21-Nov-13 19:31pm
v2
Comments
Can you debug and check what is the value of tott?
[no name] 22-Nov-13 1:24am    
yes,it's without Decimal point answer.i Change Decimal tott into Double tott same answer
What is the value of summ after the loop?
[no name] 22-Nov-13 1:40am    
decimal point value

C#
Decimal summ = 0;
for (int n = 0; n < Cusinvoicegrid0.Rows.Count; ++n)
{
     summ += Convert.ToDecimal(Cusinvoicegrid0.Rows[n].Cells[3].Text);
}
          summ =Convert.ToDecimal(summ.ToString("#,##0.00;-$#,##0.00;0.0"));
Label3.Text = summ;
let me know it works r not
 
Share this answer
 
v4
Comments
Rahul_Pandit 22-Nov-13 1:55am    
it it working or not?
[no name] 22-Nov-13 2:01am    
i try dear getting same error.Input string was not in a correct format.
[no name] 22-Nov-13 2:17am    
http://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx
Rahul_Pandit 22-Nov-13 2:19am    
now it works or not
Rahul_Pandit 22-Nov-13 2:19am    
check updated solution
You don't really need rounding. Rounding is rarely needed and can even be considered dangerous as you may accidentally loose precision if some rounding gets into intermediate results of calculation.

Instead, you just need string formatting of numeric data with proper formatting:
http://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].

—SA
 
Share this answer
 
using System.Globalization;


System.Globalization.CultureInfo culInfo = new System.Globalization.CultureInfo("hi-IN");

lbltotal.Text = total.ToString("C", culInfo).Remove(0, 2).Trim();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900