+ Reply to Thread
Results 1 to 2 of 2

Thread: Calling java methods from RPG program

  1. #1

    Default Calling java methods from RPG program

    Hi guys, I've been assigned with a task of rounding a decimal value to a scale (number of digits to the right of decimal point) and this scale actually stored in a file and they can vary based on the currency which are also stored in the same file. I tried to use %DECH or SQL function i.e ROUND to accomplice this but the scale parameter which accepted by these two functions has to be specified in number instead of an variable. So, I thought of using the java class BigDecimal which has a method called setScale and the scale parameter can be accepted as variable by this method. I've coded my RPG program to call this setScale method and to my suprise, the result seems to be correct sometimes and sometimes are not. For an example, when I pass a value of 588.985777 (this field has been defined as 23,9) and the scale has a value of 2 (which actually comes from a file) and ROUND_HALF_UP as a rounding method, the result shows a value of 588.990000000. This result to me is correct. But, if I pass the same value with a scale of 3, I get a result of 588.985999999. The weird thing this works sometimes and sometimes not. I even coded the garbage collecting routines as well. I don't know where the problem lies. I've pasted here the entire program for you guys to scrutinized and please let me know whether there are any other alternative to round a value by using a varying scale.

    ecomround

  2. #2
    K.Forsythe Guest

    Default Calling java methods from RPG program

    Floating point is not reccomended (even by IBM) for this kind of thing - under certain mathematical situations it returns an answer that is slightly off. I am not enough of a mathematician to explain that. Rather that calling Java (which is Way cool) - Try writing your own function that simply accepts a value and has a big select statement that uses %DEC with every possible scale. It will probably be faster too. Good luck, Kevin

+ Reply to Thread

Similar Threads

  1. Replies: 6
    Last Post: 08-18-2004, 05:46 AM
  2. Calling a java program from RPGIV
    By Guest.Visitor in forum RPG
    Replies: 1
    Last Post: 08-14-2003, 08:07 AM
  3. RPGLE calling Java Methods using CODE400 SmartGuide
    By Guest.Visitor in forum Dev Tools
    Replies: 0
    Last Post: 05-28-2003, 11:57 AM
  4. calling an as400 program from java
    By tkosacek@visioninfo.com in forum Java
    Replies: 2
    Last Post: 10-18-2002, 07:05 AM
  5. Calling a JAva Program through a CL
    By dkeys@oreillyauto.com in forum Programming
    Replies: 2
    Last Post: 07-12-2001, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts