Numeric Format Specifier in LightSwitch 2012

Here we will see how to use the Numeric Format Specifier in LightSwitch Visual Studio 2012.

The numeric ("N" or "n") format specifier is used to convert a number into a string form as "-d,ddd,ddd.dd", where the "-" symbol indicates a negative number that is optional, "d" indicates a digit (from 0 to 9), "," indicates a group separator, and the "." symbol indicates a decimal point. The precision is used to indicate the desired number of digits after the decimal point.

Note: Number (N) is supported by all numeric data types.

Use the following procedure to create a sample showing how to use a 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.

Student 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 the screen information, choose "Student" 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 using Editable Screen

Step 4

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

Select Fees from Student

Then go to the Format Pattern of the Property window in the Table Designer and either enter "N" in the format pattern as shown below.


Format Pattern Property Window

Or enter enter "n" in the format pattern as shown below.


n Format Pattern Properties

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

Number Format Pattern Output

We can also provide a negative value in the fees column.

Output for Negative Pattern

Step 5

We can also provide an integer value. For providing an integer value go to the Table Designer and select the "Integer" data type for Fees.

Choose Integer Data Type

Now go to the Format Pattern of the Property window in the Table Designer and enter "N" in the format pattern.

Format Pattern Property Window

Now run the application. We will get the following output as shown below.

Output For integer value