duanfengwang9157 2011-12-10 16:51
浏览 79
已采纳

具有确切总和的分期付款

is there any way to accurately calculate the installments? remembering that the sum of these parcels shall be the total value of the? I usually do a loop which will split and burn in the database, if the number of parcels is 4, I record four records .. but I want to know if there is any way that I can piecemeal parts that final sum is accurate, as X = 500, P = 3, if I dividor (500 / 3), 166.666 will give ... but the result is that I hope to get something like: X = 500, P = 3, p¹ = 150: p² = 150, p³ = 200

Legend: X = Order Value, P = Number of Parcels. , p¹, p², p³ = parcel 1, 2 and 3

Remember, the value of the order, will never be exact, I get 2598.90, 2038.80 .. etc.

  • 写回答

1条回答 默认 最新

  • doulu5109 2011-12-10 17:12
    关注

    If I understand you correctly, here is my guess

    $total = 23419.97;     // total amount
    $total_parcel = 24;    // total parcel
    
    // average parcle
    $avg_parcel = floor($total / $total_parcel); // nearest integer;
    
    // value for each parcel
    $parcels = array_fill(0, $total_parcel, $avg_parcel);
    
    // change last parcel value
    // so, sum of all parcel = total
    $parcels[$total_parcel-1] = $total-(($total_parcel-1)*$avg_parcel);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?