Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DECIMAL PORTION OF A VARIABLE 3

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
0
0
CA
hi,
i have a variable A (FOR EXAMPLE =1.25)
i need to get the decimal portion of A.
i did this:
05 A PIC 9(08)v99.
05 B redefines A.
10 B-WHOLE PIC 9(08).
10 B-DECIMAL PIC 9(02).

move A to B.
move B-decimal to A.
result:
A= 01 instead of 25 ???
what is the problem ?
thanks
 
hi claudeb,
i know this isn't much use but i'm baffled, i cut & pasted your code into my compiler and it works fine. A contains 25. is your code exactly the same as above?
you can also reduce yyour coding by deleting the move A to B statement, B redefines A and therefore they contain the same data.
Sorry i couldn't be more help but im still looking for a reason because it's bugging me now!

regards, jimlee, great wizard of Ankh Morpork.
 
Hi,

In the example above it is not a good idea to move b or parts of b to a or the other way around. These are called moves with overlapping storage.

Do the same thing with a separate defined field and it will probably be ok.

The outcome of the example above depends on the compiler.

Your compiler can even give a warning in those situations.

Regards,

Crox
 
forgot to thank jimlee.
i tried the crox way the first time, but didn't work. then i used a redefines. i changed the way i did my moves.
 
Hi Claude,

You could also try reference modification, if it's supported by your compiler. The mind set for this approach is that you're moving positions 9 & 10 of the field.

move A(9:2) to ws-wrk

This only works for display fields (no comp-n).

Some purists feel it's too esoteric, but it's there, so why not use it?

Hope this helps, Jack.
 
And a special note on this. When a SIGNED Field is involved, there is no guarentee that the sign (even if sign is trailing) will move with the decimal portion.

 
Hi Thane,

I assume you're only referring to situations where SIGN IS SEPARATE is used.

Regards, Jack.
 
Jack, Thane,

as before in similar cases, when manipulating parts of a numeric field, my inclination would be to:
1. always use usage display (zoned);
2. not use a sign, or split off the sign before manipulation and maybe use it later on.

Good luck,
Ron(ald).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top