パーセンテージの減少または増加を計算するために使用している次のPHPがあります。
function CalculatePercentageIncrease( $nLastMonthPeriod, $nCurrentPeriod ) {
if ( !is_numeric( $nLastMonthPeriod ) || !is_numeric( $nCurrentPeriod ) )
return 0;
if ( $nLastMonthPeriod == 0 )
return 0;
$nLastMonthPeriod = intval( $nLastMonthPeriod );
$nCurrentPeriod = intval( $nCurrentPeriod );
$nDifference = ( ( ( $nCurrentPeriod - $nLastMonthPeriod ) / $nLastMonthPeriod ) * 100 );
return round( $nDifference );
}
私が疑問に思っている問題は、$nLastMonthPeriod
が 0 で$nCurrentPeriod
10 の場合、0 ではなく 100 を返す必要があるかどうかです。