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:
So I need the following:
However, everything i've tried/found simply rounds to the nearest whole integer, or returns a normal rounded value, hence the above would return
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) lNum = 10 ^ iNum 'get the rounded number result xVal = xVar + CLng((varValue - xVar) * lNum) / lNum Return xVal End Function
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.
Does anyone have any ideas? This has been driving me crazy for days!!