MONEY
The MONEY data type stores currency amounts. Like the DECIMAL data type, the
MONEY data type stores fixed-point numbers, up to a maximum of 32 significant
digits. You can optionally include one or two whole numbers to specify the
precision (the number of significant digits) and the scale (the number of digits to
the right of the decimal point).
Unlike the DECIMAL data type which stores floating-point numbers, if its
data-type declaration specifies neither scale nor precision, MONEY values are always
stored as fixed-point decimal numbers. If you declare a MONEY data type with
only one parameter, then 4GL interprets that parameter as the precision. By
default, the scale is 2, so the data type MONEY(p) is stored internally as
DECIMAL(p,2), for p the precision (1 <= p <= 32). If no parameters are specified, MONEY
is interpreted as DECIMAL(16,2). This specifies a total of 16 significant
digits, two of which describe the fractional part of the currency value.
The largest absolute value that you can store without error as a MONEY data
type is
10**p-s -10**-s. Here p is the precision, and s is the scale. Values with an
absolute value less than 0.5 x 10**-s are stored as zero. You cannot specify the
precision nor the scale of a FORMONLY MONEY field in an 4GL form; here the
precision defaults to the smaller of 32 or (length - 2), for length the field
length from the SCREEN section layout.
On the screen, MONEY values are displayed with a currency symbol, by default,
a dollar ( $ ) sign, and a decimal ( . ) point. You can change the default
display format for MONEY values by changing the DBMONEY environment variable. 4GL
statements and keyboard input by users to fields of screen forms do not need to
include currency symbols in literal MONEY values.
The same formulae as for DECIMAL values apply to MONEY data types; round any
fractional result up to the next whole number:
When scale is EVEN: (precision + 3) /2 ; When scale is ODD: (precision + 4) /2
For example, a MONEY(13,2) variable has a precision of 13 and a scale of 2.
This requires ((13 + 3) /2) = 8 bytes of storage.