Search code examples
vbscriptvisual-studio-2017ssrs-2017

Adding $ to a number removes formatting


I'm a database guy more than a Programmer, so bear with me. I'm creating a receipt form for a point of sales software, and ran into an issue with formatting my numbers. In the number section of the textbox properties it's formatted to add a comma to any amount over a thousand (the values passed from the data set are Decimal(15,2))

When I print the number on it's own, it's formatted fine. When I add a $ to the beginning through the textbox properties, the commas go away. I assume it's because the number is converted to a string to be concatenated with the $

What I'd like to be able to do is have both the dollar sign, and the number with a comma in one text box. I believe it can be done with an if/else to determine string length, then substringing out the amount and adding commas in the code, but that seems excessively bulky.

Here's the code that prints $1000.00 instead of $1,000.00:

="$" & First(Fields!AMOUNT.Value, "DsSalesTicketReport")

Solution

  • For formatting a number as currency (per the system's locale) VBScript provides the FormatCurrency() function. The result will still be a string, though, so only use this if you don't need to do any calculations with the number.