IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Rounding off FUnction


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
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
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: 1788
Location: Bloomington, IL

PostPosted: Fri Apr 29, 2011 10:58 pm
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
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: 2455
Location: Hampshire, UK

PostPosted: Fri Apr 29, 2011 11:06 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 29, 2011 11:24 pm
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: 765
Location: Whitby, ON, Canada

PostPosted: Fri Apr 29, 2011 11:28 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top