Format Function Not Working with Currency

  • Thread starter Thread starter crferguson
  • Start date Start date
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
 
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")
 
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!
 
Back
Top