|
-
Aug 17th, 2007, 07:38 AM
#1
Thread Starter
Addicted Member
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
-
Aug 17th, 2007, 08:14 AM
#2
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)
-
Aug 17th, 2007, 08:34 AM
#3
Re: Math.Round / Math.Ceiling
 Originally Posted by MondeoST24
For 100.99 I need to return 101.00
Math.Ceiling
 Originally Posted by MondeoST24
For 95.45 I need to return 96.00
Math.Ceiling
 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
-
Aug 17th, 2007, 09:01 AM
#4
Re: Math.Round / Math.Ceiling
Code:
If (n Mod Math.Floor(n) = 0) Then
m = n + 1
Else
m = Math.Ceiling(n)
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|