en@frrom
10th March 2004, 18:49
Hi all,

Does anyone know if there is a standard function or DLL in Baan(5.0b) for calculating the difference between 2 amounts in percentage?

Example:
amount1: 300
amount2: 450
return value +50(%)


Kind regards,

En.

vinceco252
10th March 2004, 20:20
I don't know if there is a preexisting function, but the math is straigtforward:

(amount2 - amount1) / amount1

You should be able to write a function for that pretty easily.

Good luck!

Vince

en@frrom
11th March 2004, 09:54
Hi Vince,

What you mean is rather (amount2 - amount1) / (amount1 / 100).
However, that is not good enough, because you still have to consider division by 0. What if:
- amount1 = 0, amount2 > 0, then it has to be 100%.
- amount1 = 0, amount2 < 0, then it has to be -100%.
- amount1 = 0, amount2 = 0, then it has to be 0%.

Anyway, it indeed is not a big deal at all. I was just wondering if there was already a standard function for that like there are standard functions for so many continuous little calculations in Baan... I believe in following the standard Baan logic as much as possible..


En.

vinceco252
11th March 2004, 15:14
I definitely did not put the error handling or special cases in my formula; however, it looks like your formula would come out to 5000%?

Vince

en@frrom
11th March 2004, 15:23
C'mon Vince!!

amount1: 300
amount2: 450

(450 - 300) / (300 / 100)
450 - 300 = 150
300 / 100 = 3
150 / 3 = 50

Or do I have to go back to kindergarten...??!

vinceco252
11th March 2004, 15:42
The thing is, a percentage is a fraction. 0.5 = 50%, 50 = 5000%. I can see where you're getting the 50, but if you try formatting that as a percentage in something like Excel, it will come out to 5000%...

Thanks,

Vince

en@frrom
11th March 2004, 15:49
I'm not trying to re-format the result in any way, since it is already formatted as 50%...! Never mind...

Bottom line: I was wondering if there is an existing Baan function for it. Since nobody has come up with one yet, I assume there isn't...

vinceco252
11th March 2004, 15:51
Yeah, sorry, got kinda sidetracked. I'm not aware of any standard functions.

Vince

en@frrom
11th March 2004, 18:11
Just in case anyone would find it useful, hereby a function for calculating the percentual evolution between two amounts:


function domain tcprcg calc.percentage(domain tcqsl1 amnt1, domain tcqsl1 amnt2)
{
domain tcprcg prcd

if double.cmp(amnt1, amnt2, 0.001) <> 0 then
if double.cmp(amnt1, 0.00, 0.001) <> 0 then
prcd = (amnt2 - amnt1) / (amnt1 / 100)
if double.cmp(amnt1, 0.00, 0.001) < 0 then
prcd = abs(prcd)
endif
else
if double.cmp(amnt2, 0.00, 0.001) < 0 then
prcd = -100
else
prcd = 100
endif
endif
else
prcd = 0.0
endif
return(prcd)
}


Kind regards,

En.