分期付款脚本编程可以根据不同的编程语言和需求有不同的实现方式。以下是几种不同编程语言的分期付款脚本编程示例:
Python 示例
```python
def equated_monthly_installments(principal: float, rate_per_annum: float, years_to_repay: int) -> float:
monthly_rate = rate_per_annum / 12
total_months = years_to_repay * 12
monthly_payment = principal * monthly_rate * (1 + monthly_rate) total_months / ((1 + monthly_rate) total_months - 1)
return round(monthly_payment, 2)
示例输入
principal = 100000 贷款本金
rate_per_annum = 0.05 年利率
years_to_repay = 5 分期年数
计算每月还款额
monthly_payment = equated_monthly_installments(principal, rate_per_annum, years_to_repay)
print(f"每月还款额: {monthly_payment}")
```
JavaScript 示例
```javascript
function equatedMonthlyInstallments(principal, ratePerAnnum, yearsToRepay) {
const monthlyRate = ratePerAnnum / 12;
const totalMonths = yearsToRepay * 12;
const monthlyPayment = principal * monthlyRate * Math.pow(1 + monthlyRate, totalMonths) / (Math.pow(1 + monthlyRate, totalMonths) - 1);
return monthlyPayment.toFixed(2);
}
// 示例输入
const principal = 100000; // 贷款本金
const ratePerAnnum = 0.05; // 年利率
const yearsToRepay = 5; // 分期年数
// 计算每月还款额
const monthlyPayment = equatedMonthlyInstallments(principal, ratePerAnnum, yearsToRepay);
console.log(`每月还款额: ${monthlyPayment}`);
```
PHP 示例
```php
<?php
function equatedMonthlyInstallments($principal, $ratePerAnnum, $yearsToRepay) {
$monthlyRate = $ratePerAnnum / 12;
$totalMonths = $yearsToRepay * 12;
$monthlyPayment = $principal * $monthlyRate * pow(1 + $monthlyRate, $totalMonths) / (pow(1 + $monthlyRate, $totalMonths) - 1);
return round($monthlyPayment, 2);
}
// 示例输入
$principal = 100000; // 贷款本金
$ratePerAnnum = 0.05; // 年利率
$yearsToRepay = 5; // 分期年数
// 计算每月还款额
$monthlyPayment = equatedMonthlyInstallments($principal, $ratePerAnnum, $yearsToRepay);
echo "每月还款额: " . $monthlyPayment . "\n";
?>
```
Java 示例