I'm trying to convert some AS400
/RPG
code into Java
.
I was able to find an example online that mirrored what I am seeing in the code:
d elevensix s 11 6 inz(26285.88991)
d seventwo s 7 2
c eval(h) seventwo = elevensix
c eval *inlr = *on
I have written code in Java
and I am finding that the results of the rounding I see in the RPG
code, it is not matching the type of rounding I see in Java
. Here is a sample of the rounding I am doing in Java
:
private Long roundAmount(Double amount) {
return Math.round(amount);
}
In practice my code generates results that match up to the results from the RPG
code however I am finding examples which are inconsistent in the logic; some which round up as expected and others that don't.
I have worked heavily with Java; this is my first foray into RPG
. I'm honestly not even sure where to begin. For example, in the RPG
code above; how exactly is it working? I see the results of the operation being put into a variable marked with 2 decimal places; is the rounding implicit? Searching online I find the following definition for how Java handles rounding:
The Math.round() method in Java is used to round a number to its​ closest integer. This is done by adding 1/2 to the number, taking the floor of the result, and casting the result to an integer data type.
Honestly this is clear and concise. I have not found a comparable explanation for how it works in RPG
; to be clear this is programming on an AS400 which uses RPG
, but a much older version than what I believe the current standard is. However an explanation even for the modern implementation would be a start.