Php 减少数据库中值的增加

Php 减少数据库中值的增加,php,math,Php,Math,我的起始值是18,该数字每增加+1,值的增加就会减少。基本上,如果你有更多的钱,你就很难得到这个值。增幅应比上一次的增幅小2%,如下所示 现在我每跑一次就稳定增加2分 $Strengthvalue = 2 + $row['strength']; 18=+2(增加) 19=+1.96(增加) 20=+1.92(增加) 我认为您需要将符号值更改为-这样: $Strengthvalue = 2 + $row['strength']; $stengthvalue = -0.04 + $Strengt

我的起始值是18,该数字每增加+1,值的增加就会减少。基本上,如果你有更多的钱,你就很难得到这个值。增幅应比上一次的增幅小2%,如下所示

现在我每跑一次就稳定增加2分

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

我认为您需要将符号值更改为-这样:

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

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

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

如果您希望准确无舍入问题,我建议使用递归方法:

<?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

您是否为此使用数据库?如果这样做,则可以保存起始值或上一次增加。从那里,您可以计算下一个值需要增加多少