I want to be rounded off this way
13.1, round to 13.5
13.2, round to 13.5
13.3, round to 13.5
13.4, round to 13.5
13.5 = 13.5
13.6, round to 14.0
13.7, roun
I don't know if it is proper way, but it works. Try this if you want:
double doubleValue = 13.5;
double roundedValue = 0.0;
if (doubleValue.ToString().Contains('.'))
{
string s = doubleValue.ToString().Substring(doubleValue.ToString().IndexOf('.') + 1);
if (Convert.ToInt32(s) == 5)
{
roundedValue = doubleValue;
}
else
{
roundedValue = Math.Round(doubleValue);
}
}
Console.WriteLine("Result: {0}", roundedValue);