Round to 1 decimal place in C#

You’re dividing by an int, it wil give an int as result. (which makes 13 / 7 = 1)

Try casting it to a floating point first:

averagesDoubles = (sumInt / (double)ratingListBox.Items.Count);

The averagesDoubles = Math.Round(averagesDoubles, 2); is reponsible for rounding the double value. It will round, 5.976 to 5.98, but this doesn’t affect the presentation of the value.

The ToString() is responsible for the presentation of decimals.

Try :

averagesDoubles.ToString("0.0");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)