Rounding Currency Values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What would be the best way to round a currency value to the next highest
hundreth dollar? For example, $3,569.23 to $3,600.00 or $802.32 to $900.00.
Any help would be appreciated.
 
Flannel said:
What would be the best way to round a currency value to the next highest
hundreth dollar? For example, $3,569.23 to $3,600.00 or $802.32 to
$900.00.
Any help would be appreciated.

I can see two possible issues you may have with this:
What about $300.0000001? In other words, you may have some rounding
approximation leaving you with a tiny fraction of one cent above the $300
dollar mark. Would the function round the price to $400?
Secondly, what about negative amounts? Perhaps it shouldn't normally
happen, but what should your function do?
Here is an example function which addresses both of those issues:

Public Function Round100(cur As Currency) As Currency

Dim x As Currency

x = Abs(100 * (cur \ 100))

If Abs(cur) - x >= 0.01 Then
x = x + 100
End If

If cur < 0 Then
x = -1 * x
End If

Round100 = x

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top