ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

round number

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

  • round number

    hi

    is there any RPGLE command to round numbers?

    if x=27.3 i want to get 27
    if x=27.6 i want to get 28

  • #2
    Re: round number

    You can use the Half adjust on an eval statement:

    e.g.

    Code:
         d Variable1          s              2  1        
         d Variable2          s              2  0        
    
         C                   eval(h)    Variable2 = Variable1
    What the Half-Adjust does is add 5 one place to the right of the available dec places on the destination variable. i.e.

    x = 27.3, half adjusted x = 27.5, moved to result x = 27
    x = 27.8, half adjusted x = 28.3, moved to result x = 28

    The half adjust works when the destination variable has less decimal places than the original.
    You don't stop playing games because you get old, You get old because you stop playing games!

    Comment


    • #3
      Re: round number

      thank's for your help

      Comment


      • #4
        Re: round number

        I swiped this info from one of Birgitta's posts ...

        I used this in a test program with a display file, just to be able to play with the results ... t0 is my start variable.

        Code:
        C/Exec Sql                        
        C+ Set :t1 = Ceiling(:t0)         
        C/End-Exec                        
        
        C/Exec Sql                        
        C+ Set :t2 = Floor(:t0)           
        C/End-Exec                     
           
        C/Exec Sql                        
        C+ Set :t3 = Round(:t0,0)         
        C/End-Exec
        GC
        Greg Craill: "Life's hard - Get a helmet !!"

        Comment

        Working...
        X