Monday 30 September 2013

Round to 1 decimal places in C#

Round to 1 decimal places in C#

i would like to round my answer 1 decimal places. for example : 6.7,
7.3...etc But when I use Math.round...the answer always come up with no
decimal places ...for example: 6, 7
here is my code that i used:
int [] nbOfNumber = new int[ratingListBox.Items.Count];
int sumInt = 0;
double averagesDoubles;
for (int g = 0; g < nbOfNumber.Length; g++)
{
nbOfNumber[g] = int.Parse(ratingListBox.Items[g].Text);
}
for (int h = 0; h < nbOfNumber.Length; h++)
{
sumInt += nbOfNumber[h];
}
averagesDoubles = (sumInt / ratingListBox.Items.Count);
averagesDoubles = Math.Round(averagesDoubles, 2);
averageRatingTextBox.Text = averagesDoubles.ToString();

No comments:

Post a Comment