anyone can write a PHP script as this calculator that calculates the percentage of increase and decrease?
http://www.marshu.com/articles/calculate-percentage-increase-decrease-percent-calculator.php
Thank you.
If you open the source of that page, you will find following:
function PercentIncrease(form) {
var num1 = form.num1.value;
var num2 = form.num2.value;
return ((num2 - num1) / num1 * 100 + "%");
}
Let us know if you have problems with PHP syntax.
Update: Obviously you have, so:
function PercentIncrease($num1, $num2) {
return (($num2 - $num1) / $num1 * 100 . "%");
}
$n1 = 10;
$n2 = 200;
echo PercentIncrease($n1, $n2); //output 1900%
echo PercentIncrease($n2, $n1); //output -95%
You could make a function like :
function calcPercentInc($a, $b)
{
return (100 * (($a / $b) - 1)) . '%';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.