troubleshooting Question

sum doesn't work

Avatar of Lennart Ericson
Lennart EricsonFlag for Sweden asked on
PHP
7 Comments2 Solutions202 ViewsLast Modified:
With this formula (formula 1)

$summa = ($a_100*$p_100_euro+$a_200*$p_200_euro+$a_700*$p_700_euro+$a_701*$p_701_euro+$a_702*$p_702_euro+$a_703*$p_703_euro+$a_704*$p_704_euro+$a_705*$p_705_euro+$a_706*$p_706_euro+$a_707*$p_707_euro+$a_708*$p_708_euro+$a_709*$p_709_euro+$a_800*$p_800_euro+$a_801*$p_801_euro+$a_802*$p_802_euro+$a_803*$p_803_euro+$a_804*$p_804_euro+$a_805*$p_805_euro+$a_806*$p_806_euro+$a_807*$p_807_euro+$a_808*$p_808_euro+$a_809*$p_809_euro+$a_810*$p_810_euro+$a_811*$p_811_euro+$a_812*$p_812_euro+$a_813*$p_813_euro+$a_816*$p_816_euro+$a_817*$p_817_euro+$a_822*$p_822_euro+$a_830*$p_830_euro);

I get a wrong print out. It prints out $summa = 770.

Changing the formula to (formula 2):

$summa = "$a_100*$p_100_euro+$a_200*$p_200_euro+$a_700*$p_700_euro+$a_701*$p_701_euro+$a_702*$p_702_euro+$a_703*$p_703_euro+$a_704*$p_704_euro+$a_705*$p_705_euro+$a_706*$p_706_euro+$a_707*$p_707_euro+$a_708*$p_708_euro+$a_709*$p_709_euro+$a_800*$p_800_euro+$a_801*$p_801_euro+$a_802*$p_802_euro+$a_803*$p_803_euro+$a_804*$p_804_euro+$a_805*$p_805_euro+$a_806*$p_806_euro+$a_807*$p_807_euro+$a_808*$p_808_euro+$a_809*$p_809_euro+$a_810*$p_810_euro+$a_811*$p_811_euro+$a_812*$p_812_euro+$a_813*$p_813_euro+$a_816*$p_816_euro+$a_817*$p_817_euro+$a_822*$p_822_euro+$a_830*$p_830_euro";

it prints out like: 1*1 905+0*1 461+0*100+1*388+0*265+0*109+0*31+0*604+0*137+0*238+0*1 581+0*1 503+0*173+0*311+0*265+1*381+0*355+0*84+0*133+0*249+0*87+0*425+0*485+0*27+0*258+0*391+0*26+0*123+0*53+0*426

If I add it manually together I get 2674. And that is what I expected formula 1 would have given me.

What have I done to cause this miscalculation? It might be a typo, but I can't find it.

Please, gurus, advice me.
ASKER CERTIFIED SOLUTION
hmarcbower

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros