【问题标题】:Installment calculation function分期计算功能
【发布时间】:2021-10-26 18:53:01
【问题描述】:

我现有的代码计算错误,我找不到正确的代码。 例如,14.75% 的佣金,100 美元的交易,应支付 114.75 美元,而交易后却是 117.30 美元。 我在下面分享我的代码,我怎样才能正确计算?

  $install = DB::getRow("SELECT installment FROM installments WHERE id='{$k}'");

        $montly  = round($mInfo->fPrice / (1 - str_replace(",", ".", $i) / 100) / $install->installment, 2);
        $total = round($mInfo->fPrice / (1 - str_replace(",", ".", $i) / 100), 2); 

【问题讨论】:

  • str_replace() 函数返回一个 string 。您需要将此字符串转换为 int 值 - intval()floatval() 函数适合您的问题。
  • 很遗憾,它没有用。
  • 你能告诉我你是如何在你的代码中实现floatval()函数的吗? $mInfo-> fPrice$install-> installment 返回什么数据类型??
  • // $montly = round($mInfo->fPrice / (1 - intval($i) / 100) / $install->installment, 2); // $total = round($mInfo->fPrice / (1 - intval($i) / 100), 2); // $mInfo-> fPrice = 100$ // $install->installment = 3,6,9,12 分期付款月 // $i = 佣金, 14.75

标签: php function calculator


【解决方案1】:

这些代码将解决我的朋友的问题。

$montly = round(($mInfo->fPrice+(100*$i/100))/$install->installment,2); 
$total = round($mInfo->fPrice+(100*$i/100),2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2012-03-05
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多