Round(expression [,numdecimalplaces])
Rounds the number, but you don't have any control over wich direction it rounds. So;
What is the best method to always round a decimal number up?
What is the best method to always round a decimal number down?
(edit; ment round a decimal number eather up or down to a whole number)
I don't know if there is a built in thing for this but you could just split the number and if the first number after the decimal is >= 5 then round up the number on the left, else round it down.
Use the least integer function.
Quote from: Tontow on June 21, 2005, 07:40 PM
Round(expression [,numdecimalplaces])
Rounds the number, but you don't have any control over wich direction it rounds. So;
What is the best method to always round a decimal number up?
What is the best method to always round a decimal number down?
(edit; ment round a decimal number eather up or down to a whole number)
Add one or subtract one from the number and then make the value variable an integer.
It doesn't always round down. It rounds to nearest even number, Round() utilizes 'Banker's Rounding.'
Here, I found this (http://support.microsoft.com/default.aspx?scid=kb;en-us;196652) for you.
Edit:
Arithmetic Rounding:
Function RoundIt(f As Double, DecPlaces As Integer) As String
If DecPlaces <= 0 Then
f = Int(f * (10 ^ DecPlaces) + 0.5)
f = f / (10 ^ DecPlaces)
RoundIt = f
Else
RoundIt = Format(f, "#." & Left("00000000000", DecPlaces))
End If
End Function
That's from here (http://thedailywtf.com/forums/35456/ShowPost.aspx) which also has some other examples (including an oh so efficient 100 line one :P)
How about this:
Dim foo as Double
' Floor:
Integer I = Int(foo)
' Ceiling:
Integer I = IIf( Int(foo) = foo, foo, Int(foo) + 1)
Rounding is for fat people who try to lose weight
Quote from: Topaz on June 23, 2005, 05:29 AM
Rounding is for fat people who try to lose weight
Off topic... but interesting :)
Quote from: Topaz on June 23, 2005, 05:29 AM
Rounding is for fat people who try to lose weight
So your saying that there will never ever be a situation where you need to round a number in order to avoid an error? lol