DECIMAL

DECIMAL(p,s) data type is used to store fixed-point decimal numbers. This data type can contain up to 32 significant digits. The signification of precision (p) and decimal places (s) is optional. E.g. DECIMAL(10,2) indicates that a value may contain up to 10 significant digits and 2 decimal places to the right of the decimal point. The significant digits are all the digits present within the number except the leading zeros which are on the left from the decimal point. The significant digits include the digits both to the right and to the left of the decimal point. Thus number 1.567 will have 4 significant digits one of which is also the scale.

DEC is a synonym for DECIMAL.

You should be aware that if a number fits the declared precision but the number of decimal places exceeds the scale declared, the value written to a variable will be rounded. E.g. if number 1.0004 is written to a variable of DECIMAL(5,2) data type, the value assigned to the variable will be "1.00". Thus the value has less than 5 significant digits, because it is limited by the number of available decimal places. Number 1.009 will be displayed as "1.01", because it will be rounded up.

The largest absolute value that can be stored in the DECIMAL(p,s) data type is calculated using the formula:

10p-s – 10s (where ‘p’ is the precision and ‘s’ is the scale).

Values that are less than 0,5 × 10-S are stored as zeros (where ‘s’ is the scale).

It is impossible to specify precision or the number of decimal places for a formonly field of DECIMAL type. Its precision is always smaller than 32 and is equal to (length of form field – 2).

The DECIMAL data type with fixed point is usually used for storing data which require a set number of decimal places, e.g. rates or percentages and which require high precision.

Querix 4GL converts values entered for SMALLFLOAT and FLOAT data types from decimal numeration to binary numeration for storage purpose. To display data stored in these data types, Querix 4GL converts them back to decimal numeration format. Conversions may cause inaccuracy. It is advisable to use DECIMAL data type to store information for which high precision is desired.

The number stored as DECIMAL data type can have up to 32 digits to the left of the decimal point and up to 30 significant decimal digits on the right of the decimal point. The number of bytes required to store a value of DECIMAL data type is calculated using the following formulas.

 

When the scale is even:

 

When the scale is odd:

 

 

E.g. DECIMAL(10,2) requires ((10 + 3) / 2)=6 bytes of storage.

 

DECIMAL(p)

A DECIMAL(p,s) value with specified precision and scale can be manipulated by the 4GL as a value with a fixed-point. However, precision and scale are optional, if the DECIMAL data type is declared without scale and precision, it is regarded as a floating-point number with 16 significant digits which is the default precision. The significant digits are all the digits present within the number except the leading zeros which are on the left from the decimal point. The significant digits include the digits both to the right and to the left of the decimal point.

If you specify only one parameter, it is interpreted as a precision and the number will be manipulated as a floating point number with the defined precision which may be different from the default one. The exponent of such number can range from 10-130 to 10126. The absolute values can range from 1.0E-130 to 9.99E+126.

In an ANSI database, a column of a DECIMAL(p) data type will store fixed-point numbers with the precision of p and a fixed zero scale. This number will be equivalent to an integer. However, if you declare a DECIMAL(p, 0) data type the digits to the right of the decimal point will not be discarded and will be stored internally, though they will not be displayed. If you store a data value of 1.1 in the variable of DECIMAL(5, 0)  then this variable will be displayed as 1, but in Boolean expressions it will be greater than 1.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.