The below code gives wrong calucation if zero values then next row value is not adding.. why
string[] splittedFileData = fileData.Split(new string[] { "'" }, StringSplitOptions.RemoveEmptyEntries);
if (null != splittedFileData && splittedFileData.Length > 0)
{
double total = 0;
foreach (string data in splittedFileData)
{
double tempResult = 0;
if (double.TryParse(data.Trim(), out tempResult))
total += tempResult;
}
//-- display total in a template field column with lblTotal as Label control
(e.Row.FindControl("lblTotal") as System.Web.UI.WebControls.Label).Text = total.ToString();
//-- display no of data in a template field column with lblNoOfData as Label control
(e.Row.FindControl("lblNoOfData") as System.Web.UI.WebControls.Label).Text = splittedFileData.Length.ToString();
//-- display avarage in a template field column with lblAverageData as Label control
(e.Row.FindControl("lblAverageData") as System.Web.UI.WebControls.Label).Text = (total / splittedFileData.Length).ToString("##.##");
}
Member
399 Points
1101 Posts
IF Values Zero Then Calculation Not Working
Mar 26, 2017 07:44 AM|asp.ambur|LINK
Hello
This is my Gridview
The below code gives wrong calucation if zero values then next row value is not adding.. why
All-Star
31362 Points
7055 Posts
Re: IF Values Zero Then Calculation Not Working
Mar 26, 2017 08:25 AM|kaushalparik27|LINK
Because there is no single quote after 0 value. Add a single quote ' sign after 0 because you have written code to split by single quote '
also, debug and see what values you are getting in splittedFileData string array. Please try debugging your code.
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you