What if the number i want to round is a decimal.?

/// <summary>
/// Rounds a number to the closest multiple of another number.
/// </summary>
/// <example>83 rounded to closest 25 would give a value of 75 (83 is closer to 75 than 100)</example>
/// <param name="num">The number to be rounded</param>
/// <param name="closest">The value you wish to round to the closest multiple of</param>
/// <returns>The rounded value</returns>
public int Round(int num, int closest) {
    return (int)Math.Round(((double)num)/closest, 0) * closest;
}

Do you mean if num is decimal? in that case you can overload the function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.