Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB FormatCurrency

Status
Not open for further replies.

gophertee

Programmer
Oct 11, 2000
27
US
OK, need help on this one. I have a form that basically has currency data in it (i.e. $34.76). What I want to do is round this off to ($35). Basically in a nutshell remove the cents. There is a Public Function that I believe can be called. Just don't know how to do it. Should I call this Function in my code? If so, how??? Below is the RoundCurrency function. How does one call it elsewhere?


Public Function RoundCurrency(ByVal strValue As String) As Currency

Dim strCurFix As String
'format will round these values and the string will remove what is left
strCurFix = Format(strValue, "Currency")
RoundCurrency = CCur(strCurFix)

End Function

Thanks!!! [sig][/sig]
 
The CInt function converts a number (in several formats, including currency) to an integer, rounding up or down using the standard rounding rules (<.5 rounds down, >=.5 rounds up).
Also, the FormatCurrency function converts a number to a currency format. The declaration is:
FormatCurrency(Expression, NumDigitsAfterDecimal As Long = -1, ...)

Running this code will return &quot;$35&quot;:
Dim iCurr as integer
Dim strCurFix as string
strValue = &quot;$34.76&quot;
iCurr = CInt(strValue)
FormatCurrency(iCurr, 0)

This code will return &quot;$34&quot;:
Dim iCurr as Integer
dimstrCUrFix as String
strValue = &quot;$34.26&quot;
iCurr = CInt(strValue)
FormatCurrenct(iCurr, 0)

Just as a note, if you always want to round up to the next dollar, at .5 to the original value (ie, 34.76 + .5 = 35.26, which will round down to 35).

Hope this helps.

Steve
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top