Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
nallaperumal

New User

Joined: 19 Nov 2007
Posts: 23
Location: Chennai

 Posted: Fri Apr 29, 2011 10:35 pm    Post subject: Rounding off FUnction 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.

Akatsukami

Global Moderator

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

 Posted: Fri Apr 29, 2011 10:58 pm    Post subject: 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.
nallaperumal

New User

Joined: 19 Nov 2007
Posts: 23
Location: Chennai

 Posted: Fri Apr 29, 2011 11:02 pm    Post subject: Rounding off FUnction Can any one help me to do it in COBOL.
Nic Clouston

Global Moderator

Joined: 10 May 2007
Posts: 2002
Location: UK

 Posted: Fri Apr 29, 2011 11:06 pm    Post subject: Rounded function in COBOL IS working but it perhaps does not do what you want which is another thing all together.
nallaperumal

New User

Joined: 19 Nov 2007
Posts: 23
Location: Chennai

 Posted: Fri Apr 29, 2011 11:08 pm    Post subject: Rounding off FUnction Yes Rounded function is working, But not for my Requirement
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

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

 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
don.leahy

Active Member

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

 Posted: Fri Apr 29, 2011 11:28 pm    Post subject: 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.
nallaperumal

New User

Joined: 19 Nov 2007
Posts: 23
Location: Chennai

 Posted: Sat Apr 30, 2011 12:12 am    Post subject: Rounding off FUnction Thanks my code is working fine. Thanks Don and Bill Woodger
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics What is the Extract Function in JCL dharmaraok JCL & VSAM 3 Wed Jun 14, 2017 9:12 am RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us