ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

calculate an amount (integer and decimal)

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

  • calculate an amount (integer and decimal)

    Hello,

    I have a variable named nbrCopy, the value is of 3.

    I have another variable named total, the amount is 0.30.

    When, I did

    Code:
    message = 'The amount is of ' + %char(total) + ' euros';
    
    dsply message ' ' waitInput;
    The resultat is .30

    I would like to display 0.30

    By searching on Internet, I have to use %editw .

    I have tried this

    HTML Code:
    message = 'The amount is of ' + %char(%editw(total:'0  .    '));  
    dsply message ' ' waitInput;
    The result is now -> 00.0030

    I don't understand why I don't print 0.30 ?

    HTML Code:
    **free
    
    dcl-s nbrCopy packed(4:0);
    dcl-s total packed (5:2);
    
    dcl-s message varchar(50);
    dcl-s waitInput char(1);
    
    nbrCopy = 3;
    
    IF nbrCopy < 11;
    total = nbrCopy * 0.10;
    
    ENDIF;
    
    //message = 'The amount is of ' + %char(total) + ' euros';
    message = 'The amount is of ' + %char(%editw(total:'0 . '));
    dsply message ' ' waitInput;
    
    
    *INLR = *on;
    Thank you a lot for your help.

  • #2
    Hi Juliette,

    try adding the control Option keyword decedit:

    Code:
    **free
    
    ctl-opt decedit('0.');
    
    dcl-s nbrCopy packed(4:0);
    dcl-s total packed (5:2);
    dcl-s message varchar(50);
    dcl-s waitInput char(1);
    
    nbrCopy = 3;
    IF nbrCopy < 11;
    total = nbrCopy * 0.10;
    ENDIF;
    
    message = 'The amount is of ' + %char(total);
    dsply message ' ' waitInput;
    
    *INLR = *on;

    Comment


    • #3
      Hello Paolinosal,

      Thank you, it works ! :-)

      Comment


      • #4
        Decedit lets you control at a program level how the program will convert numeric to character: https://www.ibm.com/docs/en/i/7.3?to...itjobrun-value
        Decimal separator comma or full stop, leading 0 or not

        Comment

        Working...
        X