Format Function Not Working with Currency

C

crferguson

Hello all! I'm having the oddest issue trying to format a numeric
string as currency without decimals. For instance...

strSalary = "120000.56"

strSalary = Format(strSalary, "$#,##0")
'this one returns "$#,##0" literally, no number

strSalary = Format(strSalary, "C0")
'this one returns "C0" literally, no number

strSalary = Format(strSalary, "currency")
'this one actually formats the number as currency, but is has decimal
places! So close, yet so far...

Am I missing something????

Thanks you,
Cory
 
C

Charlie Brown

In order for Format to work the way you want, you must pass in a
numeric type not a string.
strSalary = Format(strSalary, "$#,##0")
'this one returns "$#,##0" literally, no number

Dim dSalary as Decimal = 120000.56
strSalary = Format(strSalary, "$#,##0")
 
C

crferguson

Thank you! That's exactly what I needed to know. I simply wrapped the
string variable in the CDbl function and it worked perfectly. I'd
thought you could format strings as numbers so long as the characters
were all numeric such as with the "currency" type.

strSalary = Format(CDbl(strSalary), "C0")

Thanks again!
 

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

Top