I have a donation Centre set up with a goal of £100.000. So far £5 has been donated and the centre is showing it as 5% Done.

I have this in my config.php

// Your goal in USD:
$goal = 100.000;

and I have this in my donate.php

// Calculating how many percent of the goal were met:
$percent = round(min(100.000*($sum/$goal),100.000));

What is missing or wrong?

There’s nothing wrong - 5 is 5% of 100 so the answer is correct. The number of zeros after the decimal point doesn’t change anything so I don’t know why you are including three zeros there particularly since the third zero represents tenths of a penny.

Maybe the op means 100k?
(In which case 100.000 should be written without the decimal point).

Yeah, some places in europe use a decimal instead of a comma… either way it shouldn’t be in there

yes that’s right I mean 100k so I got rid of the decimal point and that changes it from 5% done to 0% done and changing the goal to 50000 makes it 5% done.
Could someone explain to me what this code is for? What is the difference for the min100000 and the other 100000 as there are two 100000?

// Calculating how many percent of the goal were met:
$percent = round(min(100000*($sum/$goal),100000));


Have a look at this:
That should helpwith what you want to do.

I’ve had a look at that and not only am I bad at maths but my php knowlege is next to nothing. I’ve tried all sorts of different variations and I’m not getting the desired result/ So now I have £10 worth of donations and a goal of £100.000 showing 19% done.

here is my current setting:

$percent = round(min(100000*($sum/$goal),100000));

could someone let me know that correct way to do it?
Much appreciation

No problem:

$have = 10;
$target = 100000;
$percentage = ( $have / $target) * 100;
$percentageToTwoDecimalPlaces = round($percentage, 2);
echo "We have raised £$have, out of £$target.<br />";
echo "We have achieved $percentageToTwoDecimalPlaces% of our target";

Hope that helps.

I know your spelling this out for me but I’m still not getting it right:

With your reply I changed it to this:

// Calculating how many percent of the goal were met:
$have = 10;
$target = 100000;
$percentage = ( $have / $target) * 100;
$percentageToTwoDecimalPlaces = round($percentage, 2);

then further down the page I changed it to this:

<div class="donations">
    	<?php $percentageToTwoDecimalPlaces?>% done

the orinal was this:

// Calculating how many percent of the goal were met:
$percent = round(min(100000*($sum/$goal),100000));

and then:

iv class="donations">
    	<?php echo $percent?>% done

Can I not just change the sums in the $percent = round(min(100000*($sum/$goal),100000)); part?

Well, that would be:

$percent = round((($sum/$goal)*100), 2);

That did it!!! Having second thoughts about learning php, not sure if I will be able to grasp it

many thanks for your help

Hi hantaah,

First off, I’m glad that helped.

Secondly, don’t give up on the PHP just yet.
I know it might seem complicated, but let me explain:

We can break our statement down into various parts.


This is how we calculate the percentage.
Divide the goal by the sum, then multiply by 100.
We don’t really need the brackets, but I find it makes it easier to read, as the division is done first, then the multiplication.

Now we want to make sure that our answer is acurate to two decimal places.
In this case, we don’t have to do anything else, as 10 divided by 100,000 is 0.01.
However, this won’t always be the case (e.g. 100 divided by 100,000 is 0.1).
To make sure that a number is rounded up/down to two decimal places we use the round() function.

The syntax is like this: round(numberToRound, numberOfDecimalPlaces)

e.g. round(3.14159265359, 2) will yield 3.14

So, we want to do this: round(ourPercentage, 2).

And this equates to round(($sum/$goal)*100, 2).

Then you can just output this to the screen:

echo round(($sum/$goal)*100, 2);

Hope that helps.

ahhhh I seeeee!!! It was all going right over my head but now it makes sense. I’m not one to give up easily so I will plod on but my current course is flying through code. I feel I learn better by example, I guess I will just have to take my time, I think html and css seemed like that too when I first layed eyes on it.

Thanks very much for your time, help and explanations