Standard numeric format strings can be used to format common numeric types in the client browser. A standard numeric format string takes the form Axx, where A is an alphabetic character called the format specifier, and xx is an optional integer called the precision specifier. The precision specifier ranges from 0 to 99 and affects the number of digits in the result. Any numeric format string that contains more than one alphabetic character, including white space, is interpreted as a custom numeric format string.
Let’s change the Data Format String of the Unit Price field on the Products controller.
Start the Project Designer. In the Project Explorer, switch to the Controllers tab and double-click on Products / Fields / UnitPrice field node.
Change the Data Format String:
Property | Value |
Data Format String | C4 |
Press OK t0 save the field. On the toolbar, click Browse.
Navigate to the Products page. The Unit Price field will be formatted as currency with a precision of 4.
Below is a list of supported standard format strings. The format string can be specified either directly or in curly brackets. The currency format string from the example can be written as “C4” or “{0:C4}”.
Note that the formatting output depends on the application user interface culture.
String | Name | Description | Example |
"D" or "d" | Decimal | Result: Integer digits with optional negative sign. Supported by: Integral types only. Precision specifier: Minimum number of digits. | 1234 ("D") -> 1234 -1234 ("D6") -> -001234 |
"C" or "c" | Currency | Result: A currency value. Supported by: All numeric types. Precision specifier: Number of decimal digits. | 123.456 ("C", en-US) -> $123.46 123.456 ("C", fr-FR) -> 123,46 € 123.456 ("C", ja-JP) -> ¥123 -123.456 ("C3", en-US) -> ($123.456) -123.456 ("C3", fr-FR) -> -123,456 € -123.456 ("C3", ja-JP) -> -¥123.456 |
"N" or "n" | Number | Result: Integral and decimal digits, group separators, and a decimal separator with optional negative sign. Supported by: All numeric types. Precision specifier: Desired number of decimal places. | 1234.567 ("N", en-US) -> 1,234.57 1234.567 ("N", ru-RU) -> 1 234,57 1234 ("N", en-US) -> 1,234.0 1234 ("N", ru-RU) -> 1 234,0 -1234.56 ("N", en-US) -> -1,234.560 -1234.56 ("N", ru-RU) -> -1 234,560 |
"P" or "p" | Percent | Result: Number multiplied by 100 and displayed with a percent symbol. Supported by: All numeric types. Precision specifier: Desired number of decimal places. | 1 ("P", en-US) -> 100.00 % 1 ("P", fr-FR) -> 100,00 % -0.39678 ("P1", en-US) -> -39.7 % -0.39678 ("P1", fr-FR) -> -39,7 % |