PDA

View Full Version : Calculations part 2


Battle_Ring
11-26-2008, 06:41 PM
Ok im trying to calculate % weight loss

Right now i have
$post['percentlost'] = ceil(intval($post['weightlost']) / intval($post['leftlose']+$post['weightlost']) * 100);

BUT this is not calculating what i need it is calculating % lost of my goal
i need it to calculate my total % of weight loss

HEre are the stats

Starting Weight: 268 lbs This is field 10
Current Weight: 265 lbs This is field 11
Goal Weight: 235 lbs This is field12
Weight Lost: 3 lbs This is weightlost
Left to Lose: 30 lbs This is leftlose
Percent Lost: 10 % this is percentlost


I believe this is the formula used to calculate % lost

Original Weight minus Current Weight

Now divide your answer by your Original Weight then multiply by 100

--------------- Added 1227733026 at 1227733026 ---------------

wouldnt it be

$post['percentlost'] = ceil(intval($post['field10']) - intval($post['field11']) / intval($post['field10']) * 100);

??? but for some reason that gives me 170 %

Dismounted
11-27-2008, 03:39 AM
(Weight Lost / Left to Lose) * 100

Also, you should use floor() instead of ceil(), as values close to 100% will display 100% instead of 99%, for example.

ReCom
11-27-2008, 04:44 AM
Won't it be a problem when Current Weight == Goal Weight? (i.e. they achieve their goal weight) Because the way I see it:
Left to Lose = Current Weight - Goal Weight
If Current Weight == Goal Weight then Left to Lose = 0 thus (Weight Lost / Left to Lose) is division by zero ... :eek:

I think you should define:
Target Loss = Starting Weight - Goal Weight

Then use:
(Weight Lost / Target Loss) * 100