ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

converting character into numeric

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

  • converting character into numeric

    Hello,

    I have a character field '00000006512' which represents a numeric amount. In this case 65.12. I am trying to convert it to digits but when I use this tmpamount = %dec(PDT_LASTPMTCHA:11:2) it comes out 6512.00.

    How can I convert so it comes out 65.12?

    Thanks,

    DAC

  • #2
    Re: converting character into numeric

    Two choices that I know of:

    1. Tear the string apart in insert the decimal point prior to conversion

    -OR-

    2. tmpamount = tmpamount / 100;

    %DEC is a little misleading, reread it and you'll see what I mean!
    "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

    Comment


    • #3
      Re: converting character into numeric

      Hi dcutaia:

      Just a little variation on what MdnghtPgmr was saying.

      Try this:
      Code:
      tmpamount = %dec(PDT_LASTPMTCHA:11:2)/100
      Best of Luck
      GLS
      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

      Comment


      • #4
        Re: converting character into numeric

        thanks that does the trick!

        DAC

        Comment


        • #5
          Re: converting character into numeric

          or
          Code:
          d                 ds                                 
          d char                          11a                  
          d number                        11s 2 overlay(char)
          I'm not anti-social, I just don't like people -Tommy Holden

          Comment


          • #6
            Re: converting character into numeric

            Originally posted by tomholden View Post
            or
            Code:
            d                 ds                                 
            d char                          11a                  
            d number                        11s 2 overlay(char)
            That's slick Tom !!!
            Greg Craill: "Life's hard - Get a helmet !!"

            Comment


            • #7
              Re: converting character into numeric

              No .. Tom's just OLD!



              (Let's hear it for the Old School Rockers!)

              Comment


              • #8
                Re: converting character into numeric

                Originally posted by FaStOnE View Post
                No .. Tom's just OLD!



                (Let's hear it for the Old School Rockers!)

                i might be older than some of the people here but not all

                that technique is also more efficient for 2 reasons:
                1. no moving data between variables
                2. not additional memory is used since both fields are pointing to the same memory address
                I'm not anti-social, I just don't like people -Tommy Holden

                Comment


                • #9
                  Re: converting character into numeric

                  Originally posted by tomholden View Post
                  i might be older than some of the people here but not all
                  Hey - I resemble that remark!!


                  Jon P.

                  Comment

                  Working...
                  X