Percent ("P" or "p") Numeric Format Specifier in LightSwitch 2012

This article describes how to use the Percent ("P" or "p") Numeric Format Specifier in LightSwitch Visual Studio 2012.

This format specifier multiplies a number by 100 and converts it into a string with by a percentage symbol. The precision specifier indicates the desired number of decimal places. 

Note: This format specifier applies to all numeric types.

Use the following procedure to create a sample use of the Percent ("P" or "p") Numeric Format Specifier on a Screen.

Step 1

Open the LightSwitch Application in Visual Studio 2012 and go to the Solution Explorer.

Solution Explorer

Right-click on "Data Sources" and choose "Add Table".

Add Table

The table appears in the table designer window. Insert the records in the following table.

Employee table

Step 2

Now once again go to the Solution Explorer, right-click on "Screens" and choose "Add Screen".

Add Screen

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, inside screen information, choose "Employee" under screen data and provide some name to the Screen and click the "OK" button.

Add New Screen

The Screen Designer appears as shown below.

Application Designer

Step 3

Press F5 to run the application. Provide the information. 

Output of Editable Grid Screen

Step 4

Now stop debugging the application. From the Table designer select the "Salary" record as shown in the figure below.

Select Salary from Employee Table

Then go to the Format Pattern of Property window in the table designer and enter "P" in the format pattern as shown below.

P Format Pattern propery window

Or you can enter enter "p" in the format pattern as shown below.

p Format Pattern properties

Once again press F5 to run the application. This time we will get the following output.

Output for P format Pattern

Step 5


Once again stop debugging the application. From the Table Designer select the "Salary" record.

Then go to the Format Pattern of the Property window in the Table Designer and enter "P1" in the format pattern as shown below. Here P1 represents one digit after the decimal point.

P1 format pattern properties

Once again press F5 to run the application. Provide the information. This time we will get the following output.

Output for P1 Format Pattern


Similar Articles