Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据保单日期和分期付款日期按月计算罚款金额_C# - Fatal编程技术网

C# 根据保单日期和分期付款日期按月计算罚款金额

C# 根据保单日期和分期付款日期按月计算罚款金额,c#,C#,假设一个人在2016年7月27日购买保单,他的下一个分期付款日期是2016年8月27日 如果此人未在分期付款日付款,则可延长15天以支付分期付款。 如果他没有这样做,他必须给予罚款,即保单金额的2% 现在的情况是—— 2016年8月27日=未付款, 2016年9月27日=未付款, 2016年10月27日=支付前两个月的罚款 那么,如何用c#计算这个呢,像这样的东西应该可以做到 public decimal CalculatePayment() { DateTime

假设一个人在2016年7月27日购买保单,他的下一个分期付款日期是2016年8月27日 如果此人未在分期付款日付款,则可延长15天以支付分期付款。
如果他没有这样做,他必须给予罚款,即保单金额的2%

现在的情况是——

2016年8月27日=未付款,
2016年9月27日=未付款,
2016年10月27日=支付前两个月的罚款


那么,如何用c#

计算这个呢,像这样的东西应该可以做到

    public decimal CalculatePayment()
    {
        DateTime lastPaymentDueDate = new DateTime(2016, 7, 27);
        DateTime thisPaymentDate = new DateTime(2016, 10, 27);

        decimal policy = 10000.0M;
        decimal mthFee = 5000.0M;
        decimal mthFine = policy * 2.0M / 100.0M;
        decimal payAmount = 0.0M;
        DateTime nextPaymentDueDate = lastPaymentDueDate.AddMonths(1);

        int thisPayJulian = (int)thisPaymentDate.ToOADate();
        int nextDueJulian = (int)nextPaymentDueDate.ToOADate();

        if (thisPayJulian < nextDueJulian)
        {
            //nothing to pay
            return payAmount;
        }
        while (thisPayJulian - nextDueJulian > 15)
        {
            //deal with late payments
            payAmount += mthFine + mthFee;
            nextPaymentDueDate = nextPaymentDueDate.AddMonths(1);
            nextDueJulian = (int)nextPaymentDueDate.ToOADate();
        }
        if (thisPayJulian >= nextDueJulian)
        {
            //deal with regular payments
            payAmount += mthFee;
        }
        return payAmount;
    }
public decimal CalculatePayment()
{
DateTime lastPaymentDueDate=新日期时间(2016,7,27);
DateTime thisPaymentDate=新的日期时间(2016年10月27日);
十进制策略=10000.0M;
十进制mthFee=5000.0M;
十进制mthFine=保单*2.0M/100.0M;
十进制支付金额=0.0M;
DateTime nextPaymentDueDate=lastPaymentDueDate.AddMonths(1);
int thisPayJulian=(int)thisPaymentDate.ToOADate();
int nextDueJulian=(int)nextPaymentDueDate.ToOADate();
如果(thisPayJulian15)
{
//处理逾期付款
支付金额+=mthFine+mthFee;
nextPaymentDueDate=nextPaymentDueDate.AddMonths(1);
nextDueJulian=(int)nextPaymentDueDate.ToOADate();
}
如果(thisPayJulian>=nextDueJulian)
{
//处理定期付款
支付金额+=mthFee;
}
返回支付金额;
}
显然,在现实世界中,lastPaymentDueDate、thisPaymentDate以及政策、费用和罚款百分比都是参数,而不是这里的固定变量,但我希望您能理解


但是,我必须重复其他评论:一般来说,如果您没有显示比您自己更多的代码,人们不会非常愿意提供帮助。

希望您是stackoverflow的新手。请看一下这个,告诉我们您尝试了什么以及您遇到了什么问题。我尝试了if(extdate