ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

decimol rounding in rpg

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • decimol rounding in rpg

    Hi Friends,

    What is the best way decimol rounding in RPG.

    Before 26285.889991 --> after round should be 26285.89



    Thanks
    Sudhakar

  • #2
    Re: decimol rounding in rpg

    Code:
    d elevensix       s             11  6 inz(26285.88991)  
    d seventwo        s              7  2                   
    c                   eval(h)   seventwo      = elevensix 
    c                   eval      *inlr = *on
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: decimol rounding in rpg

      seeing this post remember an interesting thing
      allways be carefull with decimal rounding

      Code:
      Example of "Result Decimal Position" Precision Rules
      The following examples illustrate the "Result Decimal Position" precision rules: 
      Figure 123. Examples of Precision Rules
      
       *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
       * This example shows the precision of the intermediate values
       * using the two precision rules.
       
      D p1              s             13p 2
      D p2              s             13p 2
      D p3              s             13p 2
      D p4              s             15p 9
      D s1              s             13s 2
      D s2              s             13s 2
      D i1              s             10i 0
      D f1              s              8f
      D proc            pr             8p 3
      D   parm1                       20p 5 value
       
       * In the following examples, for each sub-expression,
       * two precisions are shown.  First, the natural precision,
       * and then the adjusted precision.
       
       * Example 1:
       
       /FREE
          eval    p1 = p1 * p2 * p3;
          // p1*p2        -> P(26,4); P(26,4)
          // p1*p2*p3     -> P(39,6); P(30,0) (decimal positions are truncated)
           eval(r) p1 = p1 * p2 * p3;
          // p1*p2        -> P(26,4); P(26,4)
          // p1*p2*p3     -> P(39,6); P(30,2) (decimal positions do not drop
          //               below target decimal positions)
           eval(rh)p1 = p1 * p2 * p3;
          // p1*p2        -> P(26,4); P(26,5)
          // p1*p2*p3     -> P(39,6); P(30,3) (decimal positions do not drop
          //               below target decimals + 1)
           // Example 2:
           eval    p4 = p1 * p2 * proc (s1*s2*p4);
          // p1*p2        -> P(26,4); P(26,4)
          // s1*s2        -> P(26,4); P(26,4)
          // s1*s2*p4     -> P(41,13); P(30,2) (decimal positions are truncated)
          // p1*p2*proc() -> P(34,7); P(30,3)  (decimal positions are truncated)
           eval(r) p4 = p1 * p2 * proc (s1*s2*p4);
          // p1*p2        -> P(26,4); P(26,4)
          // s1*s2        -> P(26,4); P(26,4)
          // s1*s2*p4     -> P(41,13); P(30,5)
          // p1*p2*proc() -> P(34,7); P(30,7)  (we keep all decimals since we are
          //                already below target decimals)
       /END-FREE
      "It's like a koala pooped a rainbow on my head and I can taste the colors."

      Comment

      Working...
      X