0

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;
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jbisono
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.