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
Expressions are a very powerful feature of SSRS. They enable us to show fields at run time depending on conditions. Generally expressions are written in Visual Basic and there are many built-in functions provided. We can have also custom code for expressions.
The First function returns the first value in a set of data after all sorting and filtering have been applied at the specified scope. The First function cannot be used in group filter expressions with anything except the current (default) scope.
Report expressions are the powerful features of JasperReports, which allow us to display calculated data on a report. Calculated data is the data that is not a static data and is not specifically passed as a report parameter or datasource field.
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
Note: The MSDN article has been archived to the "VS2005_General" document, which is no longer directly accessible online. Here is the excerpt of the formatting strings referenced:
Formatting Numbers
The following table lists common .NET Framework number formatting strings.
Format string, Name
C or c Currency
D or d Decimal
E or e Scientific
F or f Fixed-point
G or g General
N or n Number
P or p Percentage
R or r Round-trip
X or x Hexadecimal
You can modify many of the format strings to include a precision specifier that defines the number of digits to the right of the
decimal point. For example, a formatting string of D0 formats the number so that it has no digits after the decimal point. You
can also use custom formatting strings, for example, #,###.
Formatting Dates
The following table lists common .NET Framework date formatting strings.
Format string, Name
d Short date
D Long date
t Short time
T Long time
f Full date/time (short time)
F Full date/time (long time)
g General date/time (short time)
G General date/time (long time)
M or m Month day
R or r RFC1123 pattern
Y or y Year month
You can also a use custom formatting strings; for example, dd/MM/yy. For more information about .NET Framework formatting strings, see Formatting Types.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With