# Thread: Rounding in a function (A2000)

1. ## Rounding in a function (A2000)

How would I round this expression to 2 decimal places? fMatch = ((curYTDE + curCE) * 0.03) - curYTDM

2. ## Re: Rounding in a function (A2000)

I don't know if this is the best way to do this, but this a way that works for me.

I multiply by 100, then cast the double into a long integer using CLngo truncating the remaining decimal places, then divide by 100.

CLng((((curYTDE + curCE) * 0.03) - curYTDM)*100)/100

HTH
Chris

3. ## Re: Rounding in a function (A2000)

Thanks Chris, that works for me, too.

4. ## Re: Rounding in a function (A2000)

I don't think using CLng will work. I would use the function below as follows:

fMatch = gfRound2( ((curYTDE + curCE) * 0.03) - curYTDM)

However, you might want to round prior to the subtraction, depending on your situation.

<pre>Public Function gfRound2(ByRef RawData) As Currency
' This function rounds the "RawData" input to 2 decimal places.
gfRound2 = CCur(CCur(RawData) / 100) * 100
End Function
</pre>

5. ## Re: Rounding in a function (A2000)

Try this:

fMatch = Round(((curYTDE + curCE) * 0.03) - curYTDM,2)

There wasn't a built-in round function in earlier versions, but there is in 2000. Just be aware that it doesn't work like the Excel rounding functions. This one only rounds up if the determinant is greater than 5.

6. ## Thanks for Round function

Thanks, Charlotte, that was what I was looking for!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•