Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Rounding off FUnction

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
nallaperumal

New User


Joined: 19 Nov 2007
Posts: 23
Location: Chennai

PostPosted: Fri Apr 29, 2011 10:35 pm    Post subject: Rounding off FUnction
Reply with quote

Hi
I just want to Round of the Dollar Amount to its nearest 10 cents.

Say if i have $ 7.23 then i need to round off to $ 7.20
if i have $ 7.26 then i need to round off to $ 7.30
if i have $ - 7.26 then i need to round off to $ 7.30
if i have $ - 7.24 then i need to round off to $ 7.20

Rounded function in cobol is not working. Please help me is there any way to solve it.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1753
Location: Bloomington, IL

PostPosted: Fri Apr 29, 2011 10:58 pm    Post subject:
Reply with quote

You can use the LE functions CEExNWN (doing the scaling yourself) to get the rounded number, and CEExABS to drop the sign.

There's probably a much simpler way to do it with COBOL intrinsic functions, but as I'm not a COBOL programmer I don't know what it is.
Back to top
View user's profile Send private message
nallaperumal

New User


Joined: 19 Nov 2007
Posts: 23
Location: Chennai

PostPosted: Fri Apr 29, 2011 11:02 pm    Post subject: Rounding off FUnction
Reply with quote

Can any one help me to do it in COBOL.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1756
Location: UK

PostPosted: Fri Apr 29, 2011 11:06 pm    Post subject:
Reply with quote

Rounded function in COBOL IS working but it perhaps does not do what you want which is another thing all together.
Back to top
View user's profile Send private message
nallaperumal

New User


Joined: 19 Nov 2007
Posts: 23
Location: Chennai

PostPosted: Fri Apr 29, 2011 11:08 pm    Post subject: Rounding off FUnction
Reply with quote

Yes Rounded function is working, But not for my Requirement icon_sad.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7307

PostPosted: Fri Apr 29, 2011 11:24 pm    Post subject: Reply to: Rounding off FUnction
Reply with quote

Code:


01  W-VALUE-TO-DISPLAY COMP-3 PIC S9(8)V9.



Use something with a single decimal place:

Code:


    COMPUTE W-VALUE-TO-DISPLAY ROUNDED = your-2-decplace-field + 0 (or whatever calculation you have)
    MOVE W-VALUE-TO-DISPLAY TO your-display-field

Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 647
Location: Whitby, ON, Canada

PostPosted: Fri Apr 29, 2011 11:28 pm    Post subject:
Reply with quote

It's actually very simple. Here is the explanation of how rounding works from the Cobol Language Reference:

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.

Study this for a while and the answer will become obvious.
Back to top
View user's profile Send private message
nallaperumal

New User


Joined: 19 Nov 2007
Posts: 23
Location: Chennai

PostPosted: Sat Apr 30, 2011 12:12 am    Post subject: Rounding off FUnction
Reply with quote

Thanks my code is working fine.

Thanks Don and Bill Woodger
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us