View previous topic :: View next topic
|
Author |
Message |
dilip_bangalore
New User
Joined: 29 Sep 2011 Posts: 27 Location: India
|
|
|
|
Hi,
Does rounded option in cobol for 12.95, gives next number 13 ?
Regards,
Dilip |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
Code: |
If this is one of those "Interview questions"
The answere is: Yes, and read the manual
Else
The answere is: Test it, and read the manual
End If |
This assumes the result variable is declared without decimals. |
|
Back to top |
|
|
chandu ravichandra
New User
Joined: 10 Apr 2012 Posts: 6 Location: INDIA
|
|
|
|
Hi,
It will round it to 13..
The result variable will have 13..... |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Language Reference (emphasis added) wrote: |
ROUNDED phrase
After decimal point alignment, the number of places in the fraction of the result of
an arithmetic operation is compared with the number of places provided for the
fraction of the resultant identifier.
When the size of the fractional result exceeds the number of places provided for its
storage, truncation occurs unless ROUNDED is specified. When ROUNDED is
specified, the least significant digit of the resultant identifier is increased by 1
whenever the most significant digit of the excess is greater than or equal to 5.
|
I think this is a little unclear. The paragraph would be better split into two. Maybe like this would be clearer:
Quote: |
When ROUNDED is specified, the least significant digit of the resultant identifier is increased by 1 whenever the most significant digit of the excess is greater than or equal to 5.
When the size of the fractional result exceeds the number of places provided for its storage, truncation occurs unless ROUNDED is specified. |
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
And because of that the language Reference cant be used any more? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
:-)
How would you come to that conclusion, Peter? Second Peter, that is. In this thread, anyway. First Peter in our Hearts. |
|
Back to top |
|
|
|