View previous topic :: View next topic
|
Author |
Message |
rameshs78
New User
Joined: 12 Nov 2006 Posts: 8 Location: Singapore
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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 |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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 |
|
|
rameshs78
New User
Joined: 12 Nov 2006 Posts: 8 Location: Singapore
|
|
|
|
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 |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
or, after the calculation, you can simply move it to a field defined with only 2 decimal positions. |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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 |
|
|
VinayCM
New User
Joined: 06 Nov 2007 Posts: 36 Location: Bengaluru
|
|
|
|
Ramesh,
Move the result you are getting after calculation to a variable of PIC clause 9(2)V99. |
|
Back to top |
|
|
|