View previous topic :: :: View next topic

Author 
Message 
hsk
New User
Joined: 28 Nov 2006 Posts: 69 Location: India




Code: 
01 WSVAR1 PIC 9(9).
01 WSVAR2 PIC 9(9)V99.
COMPUTE WSVAR1 ROUNDED = (365 / 12) * 11 => 334
COMPUTE WSVAR2 = (365 / 12) * 11
COMPUTE WSVAR1 ROUNDED = WSVAR2 => 335

Do i need to store result in some variable ??
Why COMPUTE WSVAR1 ROUNDED = (365 / 12) * 11 not giving 335 directly ? 

Back to top 




sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune




answer:
in compute with rouded always gives result approximate
but in 2nd case you have not done computation
i.e 34.58 = 35
so its better you
mention
wsvar1 pic 9(9)v9
so you will get 34.6
correct me i am wronge
from 
sachin borase
pune 

Back to top 


William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3158 Location: Tucson AZ




Intermediate results?
What would
COMPUTE WSVAR1 ROUNDED = (365.0 / 12.0) * 11.0
result in? 

Back to top 


dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix




Hello,
Please look up ROUNDED in your Fine Manual. Rounded results are not approximate  they are exact to whatever you specify.
In your example, none of the fields have any decimal places defined, so only whole numbers are considered. If the "answer" was 334.9976, you would get 334. Rounding occurs with digits to the right of the decimal. Significant digits are not "rounded up". Let's say you have 1045 and divide it by 55  the answer is 19. Should that round up to 20? I don't believe so. . . . 

Back to top 


ibm4me
New User
Joined: 23 Oct 2006 Posts: 3




picture clause
PIC 9(3)V9. >1
PIC 9(3). >2
Value
123.25 (1)
123 (2)
Truncated
123.2 (1)
123 (2)
Rounded
123.3 (1)
123 (2)
The ROUNDED option takes effect when, after decimal point alignment, the result calculated must be truncated on the right hand side.
The option adds 1 to the receiving item when the leftmost truncated digit has an absolute value of 5 or greater.
Correct me if am wrong 

Back to top 


hsk
New User
Joined: 28 Nov 2006 Posts: 69 Location: India




COMPUTE WSVAR1 ROUNDED = (365.0 / 12.0) * 11.0 is resulting in 334
if i replace the formula (365.0 / 12.0) * 11.0 by number 334.58 then the ans is 335
That is what confusion is ?
If it's rounding up 334.58 to 335,
then why it is not rounding when i use formula (365.0 / 12.0) * 11.0 and not number 334.58 

Back to top 


dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix




Hello,
If you use (365.00 / 12) * 11 it will give the rounding you expect.
Previously, there was not enough precision. This from the Fine Manual:
Quote: 
Note: You must define the operands of any arithmetic statements with
enough decimal places to give the desired accuracy in the final result.



Back to top 


William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3158 Location: Tucson AZ




Well, I was close.... 

Back to top 


hsk
New User
Joined: 28 Nov 2006 Posts: 69 Location: India




oohh, thanks dick .........
that works .......... 

Back to top 


dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix




You're welcome 

Back to top 


