Numeric To Decimal Using %replace possibly

1780 pts.
AS/400 commands
This should be an easy question. My brain is fried and can not figure this out. I'm close but I'm sure one of you has a good solution. Hours# is 5 position 2 decimal. Data coming in is 7 position numeric (NO decimal). The last 2 positions are the decimal positions. I need to get the data coming in to a numeric 2 decimal filed. Free format..only. I can do it in fixed with a move. I have been trying with a %replace but I think I'm limited b/c of the deciaml positions. DHours# S 5 2 Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.


Wouldn’t dividing by 100 give you the result you want?


Martin Gilbert.

Sorry — you’ve probably solved this 15 different ways
I’m just a couple of weeks late and I know you didn’t want to do math
But this equation will round the Input70 to a 5-2 rounded on the quarter hours

QuarterHrs52 = INT(((Input70 / 100) *4 )+ 0.5) / 4


Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • RonKoontz
    That will work and I'm doing that for now. But I wanted to use %replace just for fun. I do that
    1,780 pointsBadges:
  • DanTheDane
    In the 'old days' with RPGII is was recommended not to do a division in a case like this; - us multiply instead ... (reasons: less proces to do the task !!! and smaller objectcode !!! ). In todays freeform:
        result = indata * .01;
    result: 5.2 indata: 7.0
    2,555 pointsBadges:
  • RonKoontz
    I more want to basically replace the decimal position with something else. I have some logic that I will need to do this based on 1/4's. I can use %replace to a numeric or alpha field but I can not get it to work with a decimal field. Thats kind of what I wanted to do. I want to do it with one line of code instead of 2 or three. Thanks
    1,780 pointsBadges:
  • Yorkshireman
    Just so that I understand you want a line of code which will convert In=1234512 into New= 12345.12 and the line new = In * 0.01 is not adequate? But surely, anyone who subsequently has to read and maintain the code will instantly interpret the line and understand what's going on, whereas achieving the same answer via a circuitous and obscure line of code is sowing doubt and confusion for the future.. - We've all been there - "Look at this, what's it doing? - A reverse back integer logical OR with bitwise transgression - that must be there for a deep and meaningful purpose. . . clock ticks by .. . but all I can see it doing is multiply A * B " OTOH, I find this stuff fascinating, and if it's for your personal fund of adventures in code, more power to your pencil. Yorkshireman hoping you'll publish the final solution
    6,085 pointsBadges:
  • RonKoontz
    Yes that works... But.........Lets say I want to change the decimal position to .25 or .50 or .75 or .00. I could run this through a loop to add one or subtract the 2 and then add that amount to it. All I want to do is replace the decimal part of the number. Lots of it is for personal interest but other is to keep it simple and a one liner... This also may be usefull to someone else in th future. I like interesting code solutions and I will post it as soon as a find a good solution. Thanks
    1,780 pointsBadges:
  • BigKat
    This is a good place place for a ... service program. one-liner call in the program, but I doubt you will be able to do something so complex as rounding to the nearest 0.25 in one line, so tuck the code away in the service program
    8,710 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: