Typing of intermediate results is a complex topic which has several pitfalls which may in part depend on compiler options and some limits that might appear rather unexpected.
You can look up the data type of intermediate results for arithmetic operations here. As a diagnostic aid you can also (since Enterprise PL/I V5) use the DECOMP
compiler-option to show the types of all intermediate results in the compiler listing.
So let's have a look at your special case:
For purposes of this you can treat your mynumber
as FIXED(15,0)
, the literal 100
is a FIXED(3,0)
. By the linked table the result of the division has a total of N digits and a scale of N-p1+q1-q2= N-15+0-0 decimal places. So what is N? The documentation says it's "the maximum precision for fixed decimal" - and that depends on the LIMITS(FIXEDDEC)
compiler-option. By default N is 15 so your result has 15-15=0 decimal places and 0.5 is truncated to 0.
In the second case the result of 1.0 * mynumber
has a precision of 1+p1+p2=1+2+15=17 and a scale of q1+q2 = 1+0 = 1 decimal places but because of the FIXEDDEC-Limit the precision is reduced to 15. So as above the division results in 0 decimal places.
So how to fix this? Either specify LIMITS(FIXEDDEC(31))
as compiler-option or reduce the number of digits in mynumber
to something below 15.
P.S.: the "floating point" you mention is not floating at all, it is a fixed decimal point (as opposed to java or C PL/I does distinguish between floating-point- and fixed-point-arithmetic). To get a floating point value you have to either declare a variable as FLOAT
(DEC
or BIN
) or use exponential notation on literals.