减少数据库中值的增加

时间:2017-12-06 22:33:48

标签: php math

我的起始值是18,对于该数字每增加+1,值的增加应该减少。基本上如果你有更多的东西,就更难以增加这个价值。增幅应比之前的增幅低2%,如下图所示。

现在我每次跑步都只稳定增加2。

$Strengthvalue = 2 + $row['strength'];
  • 18 = +2(增加)
  • 19 = +1.96(增加)
  • 20 = +1.92(增加)

3 个答案:

答案 0 :(得分:0)

我认为您需要将符号值更改为 - 如此:

$Strengthvalue = 2 + $row['strength'];
$stengthvalue = -0.04 + $Strengthvalue // to decrease current value

答案 1 :(得分:0)

您的起始强度是静态的,因此您可以根据当前强度和起点的差异来计算增量。

$currentStrength = $row["strength"];
$increment = (1 - ($currentStrength - 18) * 0.02) * 2;
$StrengthValue = $increment + $currentStrength;

答案 2 :(得分:0)

如果你想要精确而没有舍入问题,我建议使用递归方法:

<?php

function calculate_increase($current_strength) {
  if($current_strength == 18) {
      return 2;
  }

  return 0.98 * calculate_increase($current_strength-1);
}
//calculate_increase(20) == 1.9208
相关问题