Author |
Message
|
bharu |
Posted: Thu Nov 30, 2017 10:40 am Post subject: Need Guidance in the EVAL rounding to the nereast interger |
|
|
Newbie
Joined: 16 Jul 2012 Posts: 9
|
Hi
I am trying to do the EVAL statement . But all the decimal value get rounded to the nearest integer value example ( value is -1.88 means its returning the value as -2). I don't want to pass the round value because it's the amount calculation.
I am not able to perform this using mathematical calculation also its completely the run time calculation.
Here i am receiving the value from other portal so they will be sending the row.col to row.coln and its not going to perform the same calculation always . it may be addition,sub,Division combination of all.
rRow.Col1 its treating as char tried with explicit casting also CAST(rRow.Col1 as decimal) that also not helping.
Example below :
---------------
Input :
(col19 * col14) + (col24 /col14 - Col19 + 10)* col19 + 20
we need to interrupt as
(rRow.col19 * rRow.col14) + (rRow.col24 /rRow.col14 - rRow.Col19 + {10})* rRow.col19 + {20}
Here rRow.col19 is going to have some value
rRow.col19 = 100
rRow.col14 = 200
rRow.col24 = 70.6
(100 * 200) + (70.6 /200 - 100 + 10)* 100 + 20 = 11055.3
return result is 11055
CODE snippet :
---------------
DECLARE dResult1,dResult2 DECIMAL 0.0;
DECLARE cDecimal,cResult,cTemp,d1 CHARACTER;
SET Environment.Variables.Col1 = '100';
SET Environment.Variables.Col2 = '7800';
SET Environment.Variables.Col3 = '12';
SET Environment.Variables.Col4 = '10';
SET Environment.Variables.Col5 = '9';
DECLARE rRow REFERENCE TO Environment.Variables;
SET cDecimal = (rRow.Col1 / rRow.Col2 - rRow.Col4 + rRow.Col3);
SET cDecimal = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(cDecimal,'(','''(''||'),'+','||''+''||'),'*','||''*''||'),'/','||''/''||'),')','||'')'''),'-','||''-''||');
SET dResult1 = EVAL(cDecimal) ;
SET dResult = CAST(EVAL(cResult) AS DECIMAL CCSID 1208);
(col24 /coL14 - Col19 + 10)
100/7800 -12+10 = actual value expected -1.98 but EVAL returned -2.
Please let us know if you need any more details |
|
Back to top |
|
 |
Vitor |
Posted: Thu Nov 30, 2017 10:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
If I had to build an evaluation engine, I can think of a number of platforms I'd use before I used IIB. Even if I had to get IIB to call out to it because I wanted IIB's transport support.
This is just contact admin, and will be a ***** to troubleshoot in production.
I suspect your problem is that you're mixing integer values and decimals, so at some point in this insanity something's being cast. Try expressing 10 as 10.0 so it's a decimal not an integer and see what happens.
Better still, try something else entirely on a different platform. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
bharu |
Posted: Thu Nov 30, 2017 11:18 am Post subject: |
|
|
Newbie
Joined: 16 Jul 2012 Posts: 9
|
Hi Vic,
Thanks for the response . Here the constraint is we don't know what value we are going to receive from the input. In this case everything is dynamic from the client .
Eg :
(78+28/90) *(78-26+89/90)
so we need to look up the col value and get the value and do the calculations.
(Row.col24+28/Row.col15)*(Row.col24-rRow.col2 +Row.col20 ) / 9
Row is the construction of the input file. so we cant convert all row values to decimal or int. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Nov 30, 2017 11:49 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
bharu wrote: |
Row is the construction of the input file. so we cant convert all row values to decimal or int. |
But you could express them all as decimals.
bharu wrote: |
Here the constraint is we don't know what value we are going to receive from the input. In this case everything is dynamic from the client |
I stand by my previous comments surrounding this ghastliness and the lack of suitability IIB brings to it. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
bharu |
Posted: Thu Nov 30, 2017 12:18 pm Post subject: |
|
|
Newbie
Joined: 16 Jul 2012 Posts: 9
|
How could the input file have character right .
You don't know which col you need to convert as decimal.
(Row.col24+28/Row.col15)*(Row.col24-rRow.col2 +Row.col20 ) / 9
expression will be evaluated and the row.col value will be picked dynamically like xml fieldname field value . |
|
Back to top |
|
 |
Vitor |
Posted: Thu Nov 30, 2017 12:44 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
bharu wrote: |
You don't know which col you need to convert as decimal. |
So you do them all as decimal.
bharu wrote: |
expression will be evaluated and the row.col value will be picked dynamically like xml fieldname field value . |
Again, I assert that this is a horrible design implemented on the wrong platform. You think you're having problems now, wait until you start running production data through it. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Dec 01, 2017 5:58 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Why restrict yourself to decimal?
Cast each of the row values as float, declare the result as a float, do the calculations on the float values.
Finally cast the result as whatever you want with whatever format you need.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|