Apr 29, 2009

I need a function which will Round a number UP to the specified decimal precision, exactly the same as how Excel's RoundUp function works:

Roundup(dblVal, intDecPlaces)

So I need the following:

Roundup(0.896523, 4)

would return

0.8966

However, everything i've tried/found simply rounds to the nearest whole integer, or returns a normal rounded value, hence the above would return

0.8965

I've tried the following:

Math.Round(dblval, intPrecision, midpointrounding.awayfromzero)

' and

Math.Round(dblval, intPrecision, midpointrounding.toeven)

And even custom functions, such as:

Public Function RoundUp(ByVal varValue As Object, _

ByVal iNum As Integer) As Double

'ignore the data types here, I was playing to see 'if changing any of the data types would swing 'the results (knowing full well they wouldnt make 'a difference, thats how fed up with this I am!)

Dim lNum As Long, xVal As Double, xVar As Object

xVar = Fix(varValue)

[CODE]...

I've even looked at converting this to a string, looking at the Xth decimal place, and incrementing it up by 1, then converting it back to a double, while this works (sort of) it seems to be a very roughshod way of doing it, and I'd rather do it mathematically than with lots of data conversion.

View 6 Replies
View Related