View previous topic :: :: View next topic

Author 
Message 
sureshmanokar
New User
Joined: 21 Dec 2010 Posts: 11 Location: Bangalore




Hi, Can anyone please help me regarding the below scenario.
Check whether a 3rd digit in COMP3 decimal item is zero, if it is zero round it of to 2 decimal values else 3 decimal values.
For example:
77 WSNAV PIC S9(4)V9(5) COMP3.
1) If the value is 1234.56089, then it should be rounded to 1234.56
2) If the value is 1234.56789, then it should be rounded to 1234.567 

Back to top 




Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark




If you make the truncation in another field, then subtract the truncated value from the original 5 decimal value. If the difference is less than .00100 then keep the truncated value else truncate to 3 decimal places. 

Back to top 


enricosorichetti
Global Moderator
Joined: 14 Mar 2007 Posts: 10169 Location: italy




learn the difference between truncate and round...
since in Your example You truncate, the value of the third decimal digit is irrelevant and does not influence the process
otherwise if You want to round, the approach is completely wrong!
if the data refers to financial transaction rounding has also legal rules,
( improper rounding might be considered as a fraud attempt )
it might be wiser to review the process. 

Back to top 


sureshmanokar
New User
Joined: 21 Dec 2010 Posts: 11 Location: Bangalore




Enrico > I apologize for my fault in the example.
Kjeld > No truncation should happen and below is my exact requirement.
If third decimal place of WSNAV = zero
COMPUTE WSPOP ROUNDED to Twodecimalplaces = WSNAV / FN1LOADPCT
else
COMPUTE WSPOP ROUNDED to Threedecimalplaces = WSNAV / FN1LOADPCT.
 Kindly advice. 

Back to top 


enricosorichetti
Global Moderator
Joined: 14 Mar 2007 Posts: 10169 Location: italy




at this point my other comment has the priority
You are messing up the rounding rules!
have the powers of Your organization and the people who set the requirements
review their basic arithmetic skills for rounding!
one reason to ask people to post the whole story and not just the silly technicalities
is to provide better answers and not to waste time on senseless issues
the way You have exposed the whole thing does not make sense
the arithmetic approach is just plain wrong!
there is difference between the computation process and the display process
for example in italy all the IR computations must be carried on with 4 ( IIRC )
decimal digit precision and displayed with two digits 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 7869 Location: Bellevue, IA




Quote: 
2) If the value is 1234.56789, then it should be rounded to 1234.567 
sureshmanokar, either you are using a mathematical system unlike the one I learned in my younger days, or you are flat out WRONG. 1234.56789 rounded to the third decimal place would be 1234.568, not 1234.567  PERIOD. The rule was, and is, that the next digit being 5 or more causes the value to go up by one. Since 8 is more than 5, the 7 becomes an 8.
You should move the COMP3 data to a DISPLAY variable which has a PIC X redefined on it. You can then use reference modification to theck the digit you want to be zero and do your rounding (assuming that really is what you want) appropriately. 

Back to top 


Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark




sureshmanokar wrote: 
Enrico > I apologize for my fault in the example.
Kjeld > No truncation should happen and below is my exact requirement.

Unfortunately this is not Psychic Day, and your example suggested truncation so that is what I suggested. But the proceedings in this thread indicates that you have to get truncation and rounding terms clearly defined, both what they mean technically, and what they mean in your organisation and to the requirement originators.
Nevertheless, my example of testing the 3rd decimal digit uses truncation on purpose to isolate the 3 low order decimals. You can use that, or possibly some bit masking to obtain a value without the 3 low order decimal digits.
Alternatively, you can use the method Robert suggested picking out the 3. decimal digit from a display representation of the value.
A real nerd would redefine the packed field to extract the 2. lowest byte, which would have a value of x'00' to x'09' if your requirement condition is true. 

Back to top 


sureshmanokar
New User
Joined: 21 Dec 2010 Posts: 11 Location: Bangalore




Robert sample:
Hi Robert, the value 1234.56789 rounded to the third decimal place would be 1234.568 as per our common mathematical system. I made a TYPO error in my example, my sincere apologize for that.
And thanks for your valuable suggestion...! I tried it before & got the perfect output what i need . Below is the program.
Program:
WORKINGSTORAGE SECTION.
01 WSPOPNAVGROUP.
05 WSPOP PIC S9(4)V9(5) COMP.
05 WSNAV PIC S9(4)V9(5) COMP.
05 WSNAVNUMERIC PIC S9(4)V9(5).
05 WSBRKPTPOPTHREE PIC S9(4)V9(3).
05 WSBRKPTPOPTWO PIC S9(4)V9(2).
77 I PIC 9(2) VALUE 0.
PROCEDURE DIVISION.
MAINPARA.
MOVE 1234.56789 TO WSNAV.
DISPLAY 'WSNAV :' WSNAV.
MOVE WSNAV TO WSNAVNUMERIC.
DISPLAY 'WSNAVNUM :' WSNAVNUMERIC.
IF WSNAVNUMERIC(7:1) = 0
COMPUTE WSBRKPTPOPTWO ROUNDED= WSNAV
MOVE WSBRKPTPOPTWO TO WSPOP
DISPLAY 'WSPOP :' WSPOP
ELSE
COMPUTE WSBRKPTPOPTHREE ROUNDED= WSNAV
MOVE WSBRKPTPOPTHREE TO WSPOP
DISPLAY 'WSPOP :' WSPOP
ENDIF.
STOP RUN.
My sincere thanks to Robert & Kjeld for their patience 

Back to top 


