General ("G") Format Specifier in LightSwitch 2012

This article describes how to use the General ("G") Format Specifier in LightSwitch Visual Studio 2012.

The general ("G") format specifier converts a number, either in fixed-point or in scientific notation depending on what the type is of the number and whether a precision specifier is present. The precision specifier determines the maximum number of significant digits that can appear in the resultant string.

Fixed-point notation is always used whenever the exponent in scientific notation is greater than -5 and less than the precision specifier; otherwise, scientific notation is used. The result contains a decimal point on the basis of requirements, and trailing zeros after the decimal point are omitted.

If the precision specifier is present and the number of significant digits in the result exceeds the specified precision then the excess trailing digits are removed by rounding. If the number is decimal and the precision specifier is omitted then fixed point notation is always used and trailing zeros will remain preserved.


Use the following procedure to create a sample showing how to use 
the General("G") 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 using G Format Pattern

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 the Property window in the Table Designer and enter "G" in the format pattern as shown below.


G Format Pattern

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


g format pattern properties

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

Output using G Format Pattern

Step 5

In the following step the digits of a number will be rounded.

Once again,
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 the Property window in the Table Designer and enter "G4" in the format pattern as shown below.


G4 format pattern

Once again press F5 order to run the application. Provide the information.

Output using G Format Pattern

This time we will get the following output. In the output the number will be rounded.

output using G4 format pattern

Step 6

In this step I will be using a number in exponential form as shown below.

Go to the Format Pattern of the Property window in the Table Designer and enter "G" in the format pattern as shown below.

G Format Pattern

Once again press F5 to run the application. Provide the following information.

output using exponent in Salary

Click on the "Save" button and this time we will get the following output.

Resultant output after save


Similar Articles