views:

7324

answers:

5

I am trying to figure out the style string for the Format(Expression as Object, Style as String) function in a Reporting Services expression.

I can't find where these style format strings are documented!

Specifically I am trying to format a Price field to be always 2 decimal places.

ie 1.5 formats to $1.50

A: 

You can check the schema at http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition/ReportDefinition.xsd

Search for xsd:complexType name="StyleType"

This will list out all the possible Styles you can use.

Specific to your question however, you can use the Format style.

Format

Specify the data format to use for values that appear in the textbox.

Valid values include Default, Number, Date, Time, Percentage, and Currency.

Link to MSDN: http://msdn.microsoft.com/en-us/library/ms251684(VS.80).aspx

Jon
A: 

Have you tried here?

http://msdn.microsoft.com/en-us/library/ms157406.aspx

Roy Rico
+2  A: 

Format with Currency format string

=Format(Fields!Price.Value, "C")

It will give you 2 decimal places with "$" prefixed.

You can find other format strings on MSDN: Adding Style and Formatting to a ReportViewer Report

Sung Meister
This is the correct answer to my specific question... I had tried that previously but I also had an error in my code, I put a CStr() inside of the Format function. I had to change Format(CStr(Fields!Price.Value), "C") to CStr(Format(Fields!Price.Value, "C"))
Jon Erickson
@Jon: Are you using "Cstr()" to append the value of formatted price to another string?
Sung Meister
+3  A: 

As mentioned, you can use:

=Format(Fields!Price.Value, "C")

A digit after the "C" will specify precision:

=Format(Fields!Price.Value, "C0")
=Format(Fields!Price.Value, "C1")

You can also use Excel-style masks like this:

=Format(Fields!Price.Value, "#,##0.00")

Haven't tested the last one, but there's the idea. Also works with dates:

=Format(Fields!Date.Value, "yyyy-MM-dd")
Peter
awesome tip. thanks peter.
Jon Erickson
A: 

Excellent thanks a lot for you help

raja