Display Formats for Numeric and Float Data in Dynamic Server Pages

In dynamic server pages, display formats for Numeric and Float data types may not be applied as expected.

Uniface and JavaScript have different standards for displaying and storing numbers, so Numeric and Float data has to be formatted for display in dynamic server pages, and deformatted for storage on the server. In some cases, numbers may be rounded for display, or it may not be possible to correctly format the data.

In addition to the data type, formatting is affected by:

  • HTML control to which the field's widget resolves. By default, this is an htmlinput widget that resolves to an HTML input control of type "text" (such as the EditBox logical widget).
  • Database interface, which may contain a packing code that specifies a scaling factor (the number of digits after the decimal)
  • Uniface display format, which may also specify scaling, depending on the field's data type

For the htmlinput of type text, Uniface supports a limited set of standard display formats for the Numeric and Float data types. These formats are not supported for type number.

Default Display Formatting

If no display format is specified, Uniface applies default formatting:

  • For Numeric data, a thousand separator is applied. If the Database Interface specifies scaling, for example I8.4, scaling is applied. Otherwise scaling is set to 0.
  • For Float data, if the database interface does not specify scaling, the data is formatted to mimic $NLS(FLOAT). If the database interface specifies scaling, it is applied.
Default Data Format Examples
Data type Database Interface Input

Displayed Value

N Not set or no scaling (I8) 123456.123456 123,456
N I8.4 123456.123456 123,456.1235
F Not set or no scaling (F8) 123456.123456 1.23456123E5
F F8.4 123456.123456 123,456.1234

Supported Display Format Codes

In DSPs, the following numeric display format codes are supported:

  • 9 (digit or leading/trailing zero)
  • z (digit with leading and trailing zeros suppressed )
  • P (decimal point)
  • K (decimal comma)
  • $NLS(Numeric)
  • $NLS(Float)
  • $NLS(FormatPattern)

The following display format codes are not supported:

  • + (plus)
  • , (comma)
  • . (dot)
  • - (minus)
  • b (suppressed zeros)
  • e (exponent)
  • $ (dollar sign)

If they are used, an exception is displayed in the web browser's console.

The following considerations also affect the way the data is formatted:

  • Locale-based formatting is applied using the value set by $webinfo("locale"), which sets the DSP client-side locale. This will affect the decimal separator and thousand separator. For more information, see $webinfo("Locale").
  • If $webinfo("locale") has not been set, NLS formats are applied but the locale defaults to "en". (The NLS locale is ignored, as it only affects server-side processing.)
  • When a Numeric or Float value has a precision higher than 16, Uniface may round the decimals when formatting the number for display, or it may display the value with an asterisk before and after the value, and return an error in the browser console.
  • For invalid display formats that include the following characters, a corrected format is applied that skips the invalid character— + (plus), - (minus), b (suppressed zeros), . (layout point), , (layout comma), or duplicate P (fixed decimal point).

    For example, -999P99 is corrected to 999P99 (minus sign is skipped), and 99P99P99 becomes 99P9999.

  • After format code P, only codes z or 9 are accepted. If one z occurs after the P, all codes after the p are converted to z. Thus, 999P99z is equivalent to 999Pzzz.
  • If a display format pattern consists of illegal characters, or it contains legal characters that are combined into an invalid display format, a compiler warning is issued, the display format is ignored, and the scaling defined by the database interface is applied.
Valid Data Format Examples
Data type Display Format Input

Displayed Value

(en_US)

Displayed Value

(fr_FR)

N DIS(99999) 123.45 00123 00123
N DIS(zzzzz) 123.45 123 123
N or F DIS(999P99) 123.45 123.45 123,45
N or F DIS(999P99) -123.45 -123.45 -123,45
N or F DIS(zzz9P9zzzz) 012.120 12.12 12,12
N or F DIS(zzz9K9zzzz) 012.120 12.12 12,12

$NLS Display Formats

The display formats $NLS(Numeric), $NLS(Float), and $NLS(FormatPattern) are supported for fields with Numeric or Float data type and the htmlinput widget of type text.

  • DIS($NLS(Numeric)) applies the thousand separator appropriate to the locale and rounds to 3 decimal points.
  • DIS($NLS(Float)) applies the decimal separator appropriate to the locale and converts the number to exponential notation.
  • DIS($NLS(FormatPattern)) applies the thousand separator appropriate to the locale, and the number of digits after the decimal as specified by the FormatPattern.
$NLS Format Examples for Data Type N or F
Locale Database Interface Display Format User Input Internal Value Displayed Value
en_US I8.2 or F8.2 DIS($NLS(Numeric)) 123456.45 123456.45 123,456.45
nl_NL
I8.4 or F8.4 DIS($NLS(Numeric)) 1234567,123456 1234567.123456 1.234.567,123
fr_CA
I8 or F8 DIS($NLS(Numeric)) 1234567,123456 1234567.123456 1 234 567,123
en_US
I8.4 or F8.4 DIS($NLS(Float)) 123456.123456 1234567.123456 1.23456123456e+5
nl_NL
I8 or F8 DIS($NLS(Float)) 123456,123456 1234567.123456 1,23456123456e+5
fr_CA
I8.4 or F8.4 DIS($NLS(Float)) 123456,123456 1234567.123456 1,23456123456e+5
en_US
I8.4 or F8.4 DIS($NLS(99999P99)) 12345.6789 12345.6789 12,345.68
nl_NL
I8.4 or F8.4 DIS($NLS(99999P99)) 12345,6789 12345.6789 12 345,68
fr_CA
I8.4 or F8.4 DIS($NLS(99999P99)) 12345,6789 12345.6789 12.345,68

Error Handling

Uniface returns errors for Numeric and Float fields when it cannot format a value coming from the server or deformat a value entered by the user. This can occur in the following circumstances:

  • When an invalid display format is defined for a Numeric or Float field.
  • When the value cannot be formatted for the specified display format; for example, because the display format is too small for the value.
  • When the value cannot be formatted at all; for example, a Number is too large to be displayed, or the value contains an invalid character.

Errors that originate on the server are logged and visible in the in the browser console. This is useful during development, and enables you to correct the unsupported display format in the component.

Browser console showing data formatting error
Browser console showing data formatting error

If an invalid format is defined or if a value that cannot be correctly formatted is assigned to a field using ProcScript or JavaScript, or if server-side formatting is enabled, the field value is displayed with asterisks, and the error is logged in the browser console.

When the user enters a value that cannot be correctly formatted for display, or deformatted and stored in the database, the field is marked in error and a syntax error is displayed (if client-side syntax checking is enabled). This enables the user to correct the error.

DSP field in browser showing syntax error
User-entered value with syntax error

Display of invalid values and error
Configuration Input Method: Value Displayed Value
Data Type: Numeric | Float
DisplayFormat: DIS(999P99)
Syntax Check on Client = true
Set by user: 1234.123 1234.123
Data Type: Numeric | Float
DisplayFormat: DIS(999P99)
Syntax Check on Client = false
Set by user: 1234.123 *1234.123*

Data Type: Numeric | Float
DisplayFormat: DIS(999P99)

Set in script: 1234.123
*1234.123*

You can also customize error handling in this situation. For more information, see Data Error Handling in Web Applications and Syntax Checking in Dynamic Server Pages .

Rounding Behavior of High Precision Values

Uniface supports a higher precision (the total number of digits that can be held or stored without changing the value) than JavaScript. Depending on the packing code specified in the Database Interface, Uniface can store numbers with a precision of 32 or 38 digits, whereas JavaScript numbers have a precision of 16 digits.

To prevent data from being corrupted, Uniface checks that it can safely convert a number from Uniface to JavaScript or vice versa. Where possible, it rounds the decimal part of the value before formatting it for display, while maintaining the true value in the data layer.

When a value cannot be converted, an error is returned. It the value was set on the server, a formatting error is returned in the browser console. If it was set on the client by the user, a syntax error is displayed.

If scaling is specified in the Database Interface, or a display format is defined for the field, Uniface applies restrictions for both data entry and the display of retrieved data. Decimals of numbers with a high precision on the fractional part are rounded off based on the scaling (number of digits after the decimal) specified by the display format (if defined), or the database interface.

Data Type N

By default, the scaling factor for data type N is 0, but a scaling factor may be supplied by the field's database interface. The display format may also specify the number of decimals to be displayed.

If scaling is defined by the database interface and a display format is specified, the display format is used.

If no scaling information is available (no database interface and no display format):

  1. The decimal is rounded to the default of 0 decimal points.
  2. If the rounded value falls within the JavaScript precision, the display format is applied.
  3. If the rounded value is still too large, the value is displayed but is marked as in error, and an error is returned.

If scaling information is available:

  1. The decimal is rounded to match the number of decimals.
  2. If the rounded value falls within the JavaScript precision, the display format is applied.
  3. If the rounded value is still too large, the value is displayed but is marked as in error, and an error is returned.
Formatting Examples for Data Type N (en_US)
Value Database Interface Display Format Displayed Value from Server Displayed Value Entered by User
123456.123456789123456 123,456 123,456
123.123456789123456789 I8.4 123.1235 123.1235
123.123456789123456789 DIS(999P99) 123.12 123.12
123.123456789123456789 I8.4 DIS(999P99) 123.12 123.12
123123456789123456789.123456789123456789 *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 I8.4 *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 DIS(999P99) *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 I8.4 DIS(999P99) *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789

Data Type F

Scaling is implicit for floating point fields. When formatting values of data type F:

  1. Uniface checks whether the integer part of the value fits within the JavaScript precision.
  2. If so, the value is converted to a JavaScript number.
  3. If not, an error is returned.
Formatting Examples for Data Type F (en_US)

Field Value

Database Interface Display Format Displayed Value from Server Displayed Value Entered by User
123.123456789123456789 123.12345678912345 123.12345678912345
123.123456789123456789 F8 123.123456789123456789 123.123456789123456789
123.123456789123456789 F8.4 123.1235 123.1235
123.123456789123456789 DIS(999P99) 123.12 123.12
123.123456789123456789 F8.4 DIS(999P99) 123.12 123.12
123123456789123456789.123456789123456789 *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 F8 *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 F8.4 *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 DIS(999P99) *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789
123123456789123456789.123456789123456789 F8.4 DIS(999P99) *123123456789123456789.123456789123456789* 123123456789123456789.123456789123456789

Related Topics Link IconRelated Topics