核心代码
#region 计算投资回报
public IActionResult TZHB() { return View(); }
[HttpPost]
public IActionResult TZHB(int qishu, double benjin, double huibaolv) {
try
{
ArrayList arr = new ArrayList();
double benjin2 = benjin;// 存储每一次的本金+利息
for (int i = 0; i <= qishu; i++) {
double lirun = Math.Round( benjin2 * huibaolv,2); //每一期的利润=本息*回报率
double blhj =Math.Round( benjin2 + lirun,2); //本期的本利合计
arr.Add(new {
qishu = i,
benjin = benjin2,
lirun = lirun,
blhj = blhj,
});
benjin2 = blhj; //把本期的本金+利息作为下一期的本金
}
return Json(new { code=0,msg="success",data=arr});
}
catch (Exception ex)
{
return Json(new { code=-1,msg="出错:"+ex.Message});
}
}
#endregion