本文介绍了EMI计算(数据类型中的问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..
在我的应用程序中,我实现了EMI计算器..
在整个计算中使用十进制数据类型..
在这里我没有得到完整的十进制值.所以总值不匹配..
我用long,double替换了类型....仍然没有得到...
请给我一个好的解决方案..
在此先感谢
这是我的代码
Hi..
In my application I have implemented EMI calculator..
Decimal datatype is used throughout the calculation..
Here I am not getting the full decimal value..So the Total value getting mismatch..
I have replaced the type with long,double….Still not getting…
Please give me a good solution..
Thanks in advance
This is my code
Decimal Interest = 0;
EMICalculatorList ECL = new EMICalculatorList();
ProjectXBL.Config.EMICalculator EC;
int month = ddlMonth.SelectedValue.ToNonNullInt32() - 1;
Decimal Intr = 0; Decimal Mth = txtPrinciple.Text.ToNonNullDecimal() / txtLoanDurationInMonths.Text.ToNonNullDecimal();
Decimal principalAmt = txtPrinciple.Text.ToNonNullDecimal();
Decimal ROI = txtAnnualInterestRate.Text.ToNonNullDecimal();
Decimal months = txtLoanDurationInMonths.Text.ToNonNullDecimal();
Decimal F = 1200;
for (int i = 0; i < txtLoanDurationInMonths.Text.ToNonNullInt32(); i++)
{
Intr = Intr + ((principalAmt * ROI) / F);
principalAmt = principalAmt - Mth;
}
Decimal Avg = Intr.ToNonNullDecimal() / txtLoanDurationInMonths.Text.ToNonNullDecimal();
Decimal MonthlyPayment = ((txtPrinciple.Text.ToNonNullDecimal() / txtLoanDurationInMonths.Text.ToNonNullDecimal()) + Avg).ToNonNullDecimal();
lblMonthlypaymentsText.Text = string.Empty;
lblMonthlypaymentsText.Text = Math.Round(MonthlyPayment, 2).ToString();
lblAnnulLoanPaymentsText.Text = string.Empty;
lblAnnulLoanPaymentsText.Text = Math.Round((MonthlyPayment * 12), 2).ToString();
Decimal Ending = 0;
Decimal Ints = 0;
Decimal Prnc = 0;
Decimal CumPrinc = 0;
Decimal CumIntr = 0;
Decimal principal = txtPrinciple.Text.ToNonNullDecimal();
for (int i = 0; i < txtLoanDurationInMonths.Text.ToNonNullInt32(); i++)
{
EC = new ProjectXBL.Config.EMICalculator();
//No,Month And Year
EC.No = i + 1;
if (month == 0)
{
EC.Year = txtYear.Text;
}
if (month == 12)
{
month = 0;
EC.Year = (txtYear.Text.ToNonNullInt32() + 1).ToString();
}
EC.Month = ddlMonth.Items[month].Text; month++;
//
EC.Payment = MonthlyPayment;
Decimal monthly = principal / months;
//Monthly payable without interest
EC.Interest = (principal * ROI) / 1200;
Ints = EC.Interest;
principal = principal - monthly;
Interest = Interest + EC.Interest;
EC.Principal = MonthlyPayment - EC.Interest;
Prnc = EC.Principal;
if (i == 0)
{
EC.BeginningBalance = txtPrinciple.Text.ToNonNullDecimal();
EC.CumulativePrinciple = EC.Principal;
EC.CumulativeInterest = EC.Interest;
}
else
{
EC.BeginningBalance = Ending;
EC.CumulativePrinciple = CumPrinc + Prnc;
EC.CumulativeInterest = CumIntr + Intr;
}
EC.Ending = EC.BeginningBalance - EC.Principal;
Ending = EC.Ending;
CumPrinc = EC.CumulativePrinciple;
CumIntr = EC.CumulativeInterest;
ECL.Add(EC);
}
lstEMI.DataSource = ECL;
lstEMI.DataBind();
推荐答案
这篇关于EMI计算(数据类型中的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!