Jump to content

[SOLVED] find difference between percentages


kaiman

Recommended Posts

I am trying to figure out how to take a percentage of the total and return the remaining percentage i.e. 10% of 100% = 90% I have a variable called $percentage_needed that I am trying to subtract from another variable $percentage_received but I am a little stumped by the syntax for the operators. Can anyone help?

 

Thanks a ton!

 

kaiman

 

Code below:

 

<?php

// total dollar amount of donations needed
$total = "500.75";

// total dollar amount of donations received
$donations = "20.45";

// total dollar amount of sales recieved
$sales = "30.17";

// figure out percentage of total donations
$percent1 = ($donations * 100) / $total;
$percent2 = ($sales * 100) / $total;
$percentage_needed = ; 

// format numbers for dollar amount
$total = number_format($total, 2);
$donations = number_format($donations, 2);
$needed = number_format($needed, 2);
$total_received = number_format($total_received, 2);
$percent1 = number_format($percent1, 0);
$percent2 = number_format($percent2, 0);
$percentage_received = number_format($percentage_received, 0);
$percentage_needed = number_format($percentage_needed, 0);

// total dollar amount received
$total_received = $donations + $sales;

// total percentage received
$percentage_received = $percent1 + $percent2;

// total donations still needed
$needed = $total - $donations - $sales;

// total percent of donations recieved
echo "Total expenses: $".$total."<br /> \n";
echo "Total donations: $".$donations." (<strong>".$percent1."%</strong>)<br /> \n";
echo "Total sales: $".$sales." (<strong>".$percent2."%</strong>)<br /><br /> \n";
echo "Total received: $".$total_received." (<strong>".$percentage_received."%</strong>)<br /><br /> \n";
echo "Amount needed: $".$needed." (<strong>".$percentage_needed."%</strong>)";
?>

Link to comment
Share on other sites

corbin,

 

Thanks for the reply. Not sure what you mean by "retain the weight" but what I am trying to due is figure out how to display the difference between the percentage donated and the percentage not yet donated, i.e. total percentage = 100%, percentage donated = 10%, percentage not donated = 90% (this is what I want to display). I have already calculated the percentage donated (10%), but how do I show the remaining percentage not yet donated (90%)?

 

Thanks again,

 

kaiman

Link to comment
Share on other sites

Yep, the problem is that 1 is a $ dollar amount and one is a percentage %

 

What is the PHP syntax for the equation to figure out how to subtract a percentage from the dollar amount and then convert it back to a percentage?

 

Thanks,

 

kaiman

Link to comment
Share on other sites

Okay, see my script so far for details.

 

1. I have a total amount needed: $500.75

2. I have one percentage that is purchases from the store they equal: $30.17 or 6% of $500.75

3. I have one percentage that is donations they equal: $20.45 or 4% of $500.75

4. The combined totals of $30.17 + $20.45 = $50.62

5. Of the total ($500.75) the combined totals in donations + sales ($50.62) = 10%

6. How do I create a function that subtracts the 10% ($50.62) from the total ($500.75=100%) and then convert it back to a percentage (90%) which can be displayed next to the total still needed ($500.75-$50.62 = $450.13) or as I want it displayed:

 

Total still needed $450.13 (90%)

 

The question is how do I subtract a percentage (10%) from the total ($500.75) and then display it as 90% so that when I update the other numbers the percentage of donations already and percentage of donations needed are reflective of each other? i.e. if one says 15% of donations received the other will say 85% of donations still needed...

 

Does that make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.