ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

convert number to numeric

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

  • convert number to numeric

    Hello All,

    I'm looking to convert a number to negative. Example, if num1 = 25.23, new number would be -25.23 (or 25.23-). Example 2, if num1 = -25.23, new number would be -25.23 (or 25.23-).

    Any help would be appreciated.

    Thanks,

    Pagen

  • #2
    Re: convert number to numeric

    PHP Code:
     *                                                   
    d count           s              5  0                
    d negative
    #       s              5  0                
    d worknumber      s              4  0                
                                                         
     
    /Free                                               
       
    //------------------------------------------------
       // MAIN PROGRAM                                   
       //------------------------------------------------
                                                         
           
    for count 1 to 5;                           
                                                         
            
    select;                                      
             
    when count 1;                             
              
    worknumber =  11;                          
             
    when count 2;                             
              
    worknumber =  -15;                         
             
    when count 3;                             
              
    worknumber =  250;                         
             
    when count 4;                     
              
    worknumber =  -256;                
             
    when count 5;                     
              
    worknumber =  1000;                
            
    endsl;                               
           
    negative# = %abs(worknumber) * -1;    
           
    dsply %editc(negative#:'J')  ' ';     
                                                 
           
    endfor;                               
                                                 
            *
    inlr = *on;                         
                                                 
     /
    End-Free 
    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: convert number to numeric

      Thanks for the help Jamie.

      That example worked great.

      Pagen

      Comment


      • #4
        Re: convert number to numeric

        your welcome
        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


        • #5
          Re: convert number to numeric

          Or....

          PHP Code:
          *                                                    
          d count           s              5  0                 
          d negative
          #       s              5  0                 
          d worknumber      s              4  0                 
                                                                
          /Free                                                
             
          //------------------------------------------------ 
             // MAIN PROGRAM                                    
             //------------------------------------------------ 
                                                                
                 
          for count 1 to 5;                            
                                                                
                  
          select;                                       
                   
          when count 1;                              
                    
          worknumber =  11;                           
                   
          when count 2;                              
                    
          worknumber =  -15;                          
                   
          when count 3;                              
                    
          worknumber =  250;                          
                   
          when count 4;                      
                    
          worknumber =  -256;                 
                   
          when count 5;                      
                    
          worknumber =  1000;                 
                  
          endsl;                                
                 
          negative# = 0 - %abs(worknumber);     
                 
          dsply %editc(negative#:'J')  ' ';      
                                                        
                 
          endfor;                                
                                                        
                  *
          inlr = *on;                          
                                                        
          /
          End-Free 
          Predictions are usually difficult, especially about the future. ~Yogi Berra

          Vertical Software Systems
          VSS.biz

          Comment


          • #6
            Re: convert number to numeric

            see how they are... those MBA's making things so complicated you cant read em
            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


            • #7
              Re: convert number to numeric

              One million and one different ways to do something...

              Comment


              • #8
                Re: convert number to numeric

                Ha ha ha ha ha.
                Predictions are usually difficult, especially about the future. ~Yogi Berra

                Vertical Software Systems
                VSS.biz

                Comment


                • #9
                  Re: convert number to numeric

                  Originally posted by jamief View Post
                  see how they are... those MBA's making things so complicated you cant read em
                  Except that subtracting the number from zero is many times faster than multiplying the number by negative one. (I seem to recall we've had this disucssion before!)
                  "Time passes, but sometimes it beats the <crap> out of you as it goes."

                  Comment


                  • #10
                    Re: convert number to numeric

                    Hi Pagenbeast,

                    As regarding your Question i dont think that this is too Complicated The Simple Way is to do this is :-- like if you take your variable name is "Number" or any one this is upto you

                    Give logic like that if your variable is in +ve Example: 25.23

                    then ,

                    IF Number > 0
                    Eval Number = Number * (-1)
                    Endif

                    and if Number is -25.23 then there is no logic behind this
                    Last edited by satyadeep; November 1, 2007, 12:06 AM.
                    Satya

                    Comment


                    • #11
                      Re: convert number to numeric

                      many times faster ....... how bout a couple nano-seconds faster .....that wouldnt even win a
                      NASCAR race
                      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


                      • #12
                        Re: convert number to numeric

                        Hello All,

                        I originally used Satya's version, but then switched to the %ABS(Num) * -1 as it looks nicer.

                        Pagen

                        Comment


                        • #13
                          Re: convert number to numeric

                          Hello

                          Pagen,
                          As regarding your questions
                          i don't think that here there is any use of Absoulate values if u want to use its ok but using of any &#37;BIF values and any other line of code have to make sense and here i am not gettinf any sense of using this because all times you want -(VE) values so simply use the code which i sent you u know waht is the use of absoulate values it means it will convert negative to positive values if you use like that -
                          if Num= - 25.30
                          num=%ABS(Num)

                          this will come like that = 25.30 and

                          and how u used there is not any use to make like this

                          num= %ABS(Num) * -1 or num=Num*(-1)

                          same result

                          if u want to think that code will look nicer then its different

                          enjoy with code

                          satya
                          Satya

                          Comment

                          Working...
                          X