the following error occured while round the value ("Index was outside the bounds of the array.")
my code behind is..
double present = Convert.ToDouble(upnoodP.Text);
double X = 100;
double totaldays = Convert.ToDouble(uptwd.Text);
double total = (present * X) / totaldays;
string[] str = total.ToString().Split('.');
double no1 = Convert.ToDouble("0." + str[1]);
double result;
if (no1 < 0.51)
{
result = Math.Floor(total);
uppercent.Text = Convert.ToString(result) + "%";
}
else
{
result = Math.Round(total);
uppercent.Text = Convert.ToString(result) + "%";
}
how to resolve this error...
Loading

Posted Oct 15, 2013, 8:54 AM
string[] str = total.ToString("0.00").Split('.');
VulpesPosted Oct 15, 2013, 9:18 AM
double present = Convert.ToDouble(upnoodP.Text);
double X = 100;
double totaldays = Convert.ToDouble(uptwd.Text);
double total = (present * X) / totaldays;
int result = (int)Math.Ceiling(total - 0.5001);
uppercent.Text = Convert.ToString(result) + "%";
selva kumarPosted Oct 15, 2013, 9:16 AM
Posted Oct 15, 2013, 8:48 AM
You need to use, string.Format, to get the .00 in the string.