Decimal Type

Use the Decimal primitive type to define a variable with a fixed-precision and decimal point; for example, a monetary value such as a bank balance.

You must specify a decimal descriptor for the integer length of the decimal variable; for example, code d : Decimal [4]; to specify a length of 4. You can optionally specify the number of decimal places for the decimal variable; for example, code d : Decimal [4,3]; to specify that the variable is to be to three decimal places. (If the number of decimal places is not specified, it is assumed to be zero.)

The value of the integer length must be in the range 1 through 23. The number of decimal places must be equal to or less than the length value of the decimal descriptor.

As the decimal value for zero (0) has no fixed precision or scale factor, you can assign this value to any Decimal value. When this value is output (for example, by a write instruction), the scale factor of the property or variable defines the number of decimal places that are displayed. Null decimal values are initialized with a value of zero (0).

When performing decimal arithmetic, only the final assignment result is rounded. For example:

vars
    a      : Decimal[12,4];
    b, tot : Decimal[12,2];
begin
    a := 4.9350;
    b := a;
    tot := tot + a + a;
    write b;            // outputs 4.94, being the final assignment result
    write tot;          // outputs 9.87
end;

Any intermediate result keeps as much precision as possible, to minimize the overall rounding loss. To force the rounding or truncation of intermediate results, use the roundedTo or truncatedTo method, respectively. You can use the JadeEditMask class and TextBox class getTextAsDecimal and setTextFromDecimal methods to handle locale formatting for numeric fields.

For details about the methods defined in the Decimal primitive type, see "Decimal Methods", in the following subsection. For details about converting primitive types, see "Converting Primitive Types", in Chapter 1 of the JADE Developer’s Reference.