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

How to truncate the value rather than round up?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 275
Location: Bang,iflex

PostPosted: Wed Nov 14, 2007 5:31 pm
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
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
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
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: 6966
Location: porcelain throne

PostPosted: Thu Nov 15, 2007 12:06 am
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Query to Truncate value in table DB2 2
No new posts I need to copy, change and truncate f... DFSORT/ICETOOL 13
No new posts How to truncate leading zeros in EZEE... CA Products 16
No new posts CAN WE ROUND UP USING JCL SORT DFSORT/ICETOOL 14
No new posts Cobol reporting program to truncate COBOL Programming 5
Search our Forums:

Back to Top