Math.Round / Math.Ceiling
Hi,
I need my function to round an incoming decimal up to the next decimal.
For 100.99 I need to return 101.00
For 95.45 I need to return 96.00
For 50.00 I need to return 51.00
I've tried math.round and math.ceiling but there are situations when neither work. Any other ideas?
Thanks
Re: Math.Round / Math.Ceiling
So it looks like you always need the returned value to be 1 higher on the integral part of the number, eventhough the decimal part is zero. Is that correct? If so, try this
Code:
Dim num As Double = 12.0F
Dim newNum As Double = Math.Truncate(num) + 1.0F
MessageBox.Show(newNum.ToString)
Re: Math.Round / Math.Ceiling
Quote:
Originally Posted by MondeoST24
For 100.99 I need to return 101.00
Math.Ceiling
Quote:
Originally Posted by MondeoST24
For 95.45 I need to return 96.00
Math.Ceiling
Quote:
Originally Posted by MondeoST24
For 50.00 I need to return 51.00
Eh? What kind of rounding is that? Doesn't make sense.
stanav probably has the closest thing to it, but I'd use Math.Floor rather than .Truncate, then add 1 to it.
-tg
Re: Math.Round / Math.Ceiling
Code:
If (n Mod Math.Floor(n) = 0) Then
m = n + 1
Else
m = Math.Ceiling(n)
End If