Numeric To Decimal Using %replace possibly
1355 pts.
0
Q:
Numeric To Decimal Using %replace possibly
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
ASKED: May 13 2009  3:59 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
24600 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
Hi,

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

Regards,

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

Phil
_______________________________________________________________________________________
Last Answered: Jun 8 2009  9:18 PM GMT by Philpl1jb   24600 pts.
Latest Contributors: Gilly400   23625 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

RonKoontz   1355 pts.  |   May 13 2009  4:17PM GMT

That will work and I’m doing that for now. But I wanted to use %replace just for fun. I do that lots…lol

 

DanTheDane   245 pts.  |   May 16 2009  7:41PM GMT

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

 

RonKoontz   1355 pts.  |   May 18 2009  12:19PM GMT

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

 

Yorkshireman   3200 pts.  |   May 20 2009  7:34AM GMT

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

 

RonKoontz   1355 pts.  |   May 20 2009  12:03PM GMT

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

 

BigKat   2540 pts.  |   May 20 2009  2:22PM GMT

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

 
0