Quote Originally Posted by techgnome View Post
IF you are going UP to the next .05 ... which isn't rounding... try this:
Code:
	Public Sub Main()
		dim someNum as Decimal =7.5151 '5.01
		
		Console.WriteLine(someNum.ToString())
		someNum *= 100 '751.51
		Console.WriteLine(someNum.ToString())
		someNum = Math.Ceiling(someNum) '752\
		Console.WriteLine(someNum.ToString())
		someNum += (5- ((someNum + 5) mod 5)) '<--- this is the key here
		
		'Console.WriteLine((5-((someNum + 5) mod 5)).ToString)
		
		Console.WriteLine(someNum.ToString())
		someNum /= 100		
		Console.WriteLine(someNum.ToString())
		
	End Sub
https://dotnetfiddle.net/06Vzyf

PArt of the issue is you keep calling it rounding, but that isn't what you're looking for... at any rate, this gives you the results you defined with your excel screen shot. There is a little more to it than just the multiply/divide ... you also need to figure how far off from the next 5 you are. I've done this by adding 5, using mod to get the remainder, then subtracting that from 5 and adding it back to the original number. There might be a way to simplify it.

Using the above, I got 7.55 and 5.05 for the final results.

-tg
Thank you very much, your answer is very clear and I understand it

Quote Originally Posted by si_the_geek View Post
There's no need for Mod etc, just picking the right number (which is less than 100, and is the reciprocal of the 'rounding' amount) is enough.
Thanks, I multiply the value with 20 and ceiling it then divided it by 20 and get the answer
Example Code:
  1. Dim x as decimal
  2. x = math.ceiling(7.33333*20)
  3. textbox?.text = x/20
  4. ' 7.33 >> 7.35