Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to truncate the value rather than round up?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rameshs78

New User


Joined: 12 Nov 2006
Posts: 8
Location: Singapore

PostPosted: Wed Nov 14, 2007 5:06 pm    Post subject: How to truncate the value rather than round up?
Reply with quote

Hi,

I would like to truncate the value after doing a calculation, but the value should not round up.

For example, after calculation the result comes to 100.4586508
I want the value to be 100.45 only. Normally the value would get rounded up to 100.46.

How do I do this?

Thanks
Ramesh
Back to top
View user's profile Send private message

revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Wed Nov 14, 2007 5:23 pm    Post subject:
Reply with quote

Ramesh,

If you are talking about COBOL, Here is the solution

Declare variable like
01 WS-C PIC 9(03).99

Use ADD Verb without ROUND option

like ADD WS-A WS-B giving WS-C
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 276
Location: Bang,iflex

PostPosted: Wed Nov 14, 2007 5:31 pm    Post subject:
Reply with quote

Hi Revel,




Quote:
ADD WS-A WS-B giving WS-C


Could you pls tell me wat WS-A and WS-B contains, pls give us more info regarding the syntax u have used.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Wed Nov 14, 2007 5:36 pm    Post subject:
Reply with quote

Vasanth,

Lets assume, i have value

in WS-A = 50.00
WS-B = 50.4586508 <assume PIC 9(2).9(7)>

On execution of above ADD VERB, The WS-C will have value 100.45 because WS-C is declared as 9(02).99

Suppose if You are using ADD VERB with ROUNDED option like

ADD WS-A WS-B GIVING WS-C ROUNDED

Then the result will rounded to you
Back to top
View user's profile Send private message
rameshs78

New User


Joined: 12 Nov 2006
Posts: 8
Location: Singapore

PostPosted: Wed Nov 14, 2007 5:43 pm    Post subject: Reply to: How to truncate the value rather than round up?
Reply with quote

Hi Raghu,

In this case, the value would come as 100.46 only, but I want the value to be with 100.45.


Ramesh
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Wed Nov 14, 2007 6:16 pm    Post subject:
Reply with quote

rameshs78
Quote:
I would like to truncate the value after doing a calculation, but the value should not round up.

For example, after calculation the result comes to 100.4586508
I want the value to be 100.45 only. Normally the value would get rounded up to 100.46.

Results of Arthimetic calculations in COBOL will get rounded provided if u code verb ROUNDED.

If you are not coding verb ROUNDED, it will not rounded up.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Thu Nov 15, 2007 12:06 am    Post subject:
Reply with quote

or, after the calculation, you can simply move it to a field defined with only 2 decimal positions.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Thu Nov 15, 2007 9:48 am    Post subject:
Reply with quote

Ramesh,

Could you tell me what verb you are using, what is the actual reequirement (provide me varaiabel details with picture clause)

so that i can get back to you
Back to top
View user's profile Send private message
VinayCM

New User


Joined: 06 Nov 2007
Posts: 36
Location: Bengaluru

PostPosted: Thu Nov 15, 2007 10:12 am    Post subject:
Reply with quote

Ramesh,
Move the result you are getting after calculation to a variable of PIC clause 9(2)V99.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts I need to copy, change and truncate f... Charl Barnard DFSORT/ICETOOL 13 Tue Apr 01, 2014 9:06 pm
No new posts How to truncate leading zeros in EZEE... Bill Woodger CA Products 16 Mon Mar 04, 2013 1:14 pm
No new posts CAN WE ROUND UP USING JCL SORT useit DFSORT/ICETOOL 14 Fri Apr 13, 2012 11:51 am
No new posts Cobol reporting program to truncate sandhyaimmadi COBOL Programming 5 Mon Jul 18, 2011 12:22 pm
No new posts How to truncate spaces in a CSV PS fi... superman JCL & VSAM 6 Mon Mar 28, 2011 8:24 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us