Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello

I have a c# asp.net that computes the monthly repayment in a compound interest computation .

However a stored procedure which does the same produces a different results.

The codes are as follows:
The Annual interest Rate is @BRATES
The Term of the Loan is @MTERM
The Principal outstanding is @AOUTST
SQL
SET @MMCOMPCNT = @ACOMPCOUNT 
	SET @CCCMTH    = @CMONTH  
	SET @CCCYR     = @CYEAR 

											
	--COMPUTING THE DEDUCTION BEGIN
	--COMPUTING THE DEDUCTION BEGIN
	SET @MMRATE   =  @BRATES/(100*12) 
	SET @ZRATE    =  1+@MMRATE
	SET @MTERM    =  @MMCOMPCNT
	SET @MMTEMP   =  POWER(@ZRATE,@MTERM) 
	SET @MMDEDUCT = (@AOUTST*@MMRATE)/(1-(1/@MMTEMP))	
	--COMPUTING THE DEDUCTION END
	--COMPUTING THE DEDUCTION END										



-- Attached c# component

C#
case "MONTHLY REPAYMENT":

                               double xxprincipal = Convert.ToDouble(txt_Principal.Text);
                               double xxinterest   = Convert.ToDouble(txt_Interest.Text);

                               double xxmyear = Convert.ToInt32(txt_Term_Year.Text);
                               double xxmonth = Convert.ToInt32(txt_Term_Month.Text);

                               double mmrate = xxinterest/(12*100);
                               double zrate = 1 +mmrate;

                               double mterm     = 12 * xxmyear + xxmonth;

                               double mmtemp     = Math.Pow(zrate, mterm);

                               double mrepayment=(xxprincipal*mmrate)/(1-(1/mmtemp));

                               txt_Monthly.Text = mrepayment.ToString("N");
















Can you peruse the codes and offer some solution or an alternative.

Thanks

Edit (MTH): cleanup the markup
Posted
Updated 9-Sep-14 19:19pm
v4
Comments
Matt T Heffron 9-Sep-14 20:49pm    
I suggest using the "Improve question" to add the c# implementation code.
That will allow us to see where they differ.
[no name] 9-Sep-14 21:18pm    
And example input, output and an explanation of why you think it's not correct.
Member 10744248 10-Sep-14 1:17am    
case "MONTHLY REPAYMENT":

double xxprincipal = Convert.ToDouble(txt_Principal.Text);
double xxinterest = Convert.ToDouble(txt_Interest.Text);

double xxmyear = Convert.ToInt32(txt_Term_Year.Text);
double xxmonth = Convert.ToInt32(txt_Term_Month.Text);

double mmrate = xxinterest/(12*100);
double zrate = 1 +mmrate;

double mterm = 12 * xxmyear + xxmonth;

double mmtemp = Math.Pow(zrate, mterm);

double mrepayment=(xxprincipal*mmrate)/(1-(1/mmtemp));

txt_Monthly.Text = mrepayment.ToString("N");
Richard MacCutchan 10-Sep-14 5:35am    
It would be more helpful if you used exactly the same variable names in the stored procedure and the C# code, and also showed the exact values of your inputs, and the values of your results. Telling us that the results are different does not really give a clue as to how much or in what way.
j snooze 10-Sep-14 17:55pm    
You didn't post all your SQL server code, but by chance how did you define the variables? Try making your month and year variables decimals, float etc... so when doing calculations sqlserver doesn't chop off decimal points. Sometimes if its doing calculations on int variables it makes the result int. Its worth a shot anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900