Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey!

I got 3 variables:
$avegagrpsalj (this has a value of 22,20)
$avegagrpinkop (this has a value of 22,76)
$avegagrpskop (this should get a value of -2,46 after the following equation):

--------------------------(22,2)--------------(22,76)-----------(22,2)
$avegagrpskop = (($avegagrpsalj - $avegagrpinkop)/$avegagrpinkop)*100;

If I do it on my calculator:

((22,2-22,76)/22,76)*100= -2,46

I know the variables avegagrpsalj & avegagrpinkop have the right values because I do this at the end:

PHP
echo $avegagrpsalj;
echo "<br>";
echo $avegagrpinkop;
echo "<br>";
echo $avegagrpskop;


This keeps showing the value of $avegagrpskop to -3,34 instead of -2,46. I can't figure out why? :S
Posted
Updated 7-Oct-15 11:46am
v2
Comments
CHill60 7-Oct-15 18:41pm    
only thing I can suggest is to break the calculation down even further e.g.
$a = $avegagrpsalj - $avegagrpinkop
$b = &a / $avegagrpinkop
$c = $b / 100
See which bit goes wrong

1 solution

Here is why: you are way too sloppy, sorry.
Look, you only imagined that $avegagrpinkop is 22.76 and $avegagrpinkop is 22.2. It cannot be so, because this is exactly one variable. Probably you assign to $avegagrpinkop something, and then something else.

Look, you did not even show the fragment of your code. Besides, your picture with "---(22,2)..." contradicts your description and an expression below, take a look.

Believe me, it's disgusting to answer such "questions". All you need it some attention and patience. Also, the way you name variables plays destructive role. And in decent languages where the variables are required to be declared, such things simply cannot happen.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900