How to convert number to next higher multiple of five?
c#
Solution
what about this:
int x = int.Parse(maskedTextBox1.Text)/5;
int y = Math.Min(Math.Max(x,1),12)*5; // between [5,60]
// use y as the answer you need
Problem
I am coding a program where a form opens for a certain period of time before closing. I am giving the users to specify the time in seconds. But i'd like this to be in mutliples of five. Or the number gets rounded off to the nearest multiple. if they enter 1 - 4, then the value is automatically set to 5. If they enter 6 - 10 then the value is automatically set to 10. max value is 60, min is 0. what i have, but i am not happy with this logic since it resets it to 10 seconds. ``` if (Convert.ToInt32(maskedTextBox1.Text) >= 60 || Convert.ToInt32(maskedTextBox1.Text) <= 0) mySettings.ToastFormTimer = 10000; else mySettings.ToastFormTimer = Convert.ToInt32 (maskedTextBox1.Text) * 1000; ```