ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Need help understanding issue with %DECH

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

  • Need help understanding issue with %DECH

    I have the following line of code that works in production. I am now trying to reuse the module in another program and am now getting a "receiver too small for result error". Of course I've tried resizing and debugging etc...I can't see why this isn't working??

    dcl-s halfAdjustResult packed(17:5);
    dcl-s divisionResult packed(17:5);

    // When the program fails, divisionResult = -000000099999.00000
    halfAdjustResult = %dech(divisionResult:5:2);

    I tried resizing halfAdjustResult to be packed(20:8). I've tried debugging setting divisionResult = 999.00 or 999.12 just to see if I can get past this statement....

    Am I misunderstanding what %dech is supposed to do? I am thinking it will give me value round to two decimal places?? So if my divisionResult variable = 1234.56700, I am expecting 1234.57000.

    Karen


  • #2
    In your %dech you have the precision parameter set to 5 with the number of decimal places set to 2... don't you need the precision to be set larger? 5:2 only gives you enough room for 999.99 at most. Perhaps it works in your other program because the expression never gets larger than that?

    Comment


    • #3
      evawebrez02 is right. You need at least 7:2 if you want to handle the value 99999.00

      But since you're assigning it to a 17:5, which allows up to 12 integer places, you should probably code at least 14:2 for the %DECH.

      Comment


      • #4
        Thank you!!!!

        Comment

        Working...
        X