user380432
user380432

Reputation: 4779

SSRS Formatting a string to a comma number

I have the following value in one of my fileds in SSRS:

=CStr(Fields!Shipment_Weight.Value) + "#"

I do this becuase I need the #(pounds) sign at the end. This now does not allow me to format the number into something like 1,000 it gives me 1000 currently. Is there a way to add commas in the code rather than the format box since this is a string now? Values are all different from 1-1000000000

Thanks!

Upvotes: 4

Views: 33982

Answers (3)

devlin carnate
devlin carnate

Reputation: 8622

As of SSRS 2008 R2, this can be done using FormatNumber(), like so:

=FormatNumber(Sum(Fields!GrossSales.Value),0)

Intellisense shows the following definition:

FormatNumber(
   Expression As Object,    
   Optional NumDigitsAfterDecimal as Int32,
   Optional IncludeLeadingDigit as TriState,
   Optional UseParensForNegativeNumbers as TriState,
   Optional GroupDigits as TriState
) As String

You can then add the "#" to the end:

=FormatNumber(Sum(Fields!GrossSales.Value),0) & "#"

Also available under Common Functions->Text in the Expression editor:

  • FormatCurrency()
  • FormatDateTime()
  • FormatPercent()

Upvotes: 3

Ryan
Ryan

Reputation: 279

I believe the above will work, I've always used the following from MSDN

=CSTR(FORMAT(Fields!Shipment_Weight.Value,"#,#")) & "#"

The article on MSDN about string formatting

Upvotes: 2

user380432
user380432

Reputation: 4779

I found the answer it is as follows:

=CStr(FORMAT(Fields!Shipment_Weight.Value,"N0")) + "#"

That is how you use formatting code without having to put it in the formatting properties box.

Upvotes: 8

Related Questions