ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Convert from char to decimal

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

  • Convert from char to decimal

    I have to import from a file of the numerical fields (what I have to read
    alphanumeric) composed by 12 integers and 3 decimal (if negative 1°
    character of left is "- "). example:

    000000000014230 correspond to 14,23

    which could be the simplest way?
    thanks

  • #2
    Re: Convert from char to decimal

    data structure, check for bad characters first.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Convert from char to decimal

      Is it always 12 digits and three decimal positions? If so, define it as zoned-decimal and simply access it as a numeric value. Monitor for errrs in case a value isn't formatted correctly.
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment


      • #4
        Re: Convert from char to decimal

        Originally posted by gio.cot
        I have to import from a file of the numerical fields (what I have to read
        alphanumeric) composed by 12 integers and 3 decimal (if negative 1°
        character of left is "- "). example:

        000000000014230 correspond to 14,23

        which could be the simplest way?
        NumericValue = %dec(AlphaField:15:0) * 0.001;

        Comment


        • #5
          Re: Convert from char to decimal

          The data structure or zoned decimal methods won't work for negative values. You'd have to add extra code to handle the leading '-'. Ted's combination of %DEC and multiplication by .001 should work for both positive and negative values.

          Comment


          • #6
            Re: Convert from char to decimal

            Ah, right. I read the parenthetical part wrong, thinking it was about the representation of the signed digit '1'. More accurately, I didn't actually "read" it but only skimmed and then 'assumed' I understood. Ted's %DEC answer is on the mark.

            And this is the second time I've tried to post this. The one from yesterday disappeared.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment

            Working...
            X