I always get the wrong decimal in the 3rd entry of the loop. If I use the calculator, I get the right result but if I put it in excel I got the wrong result in decimal. What I want is to have the same result in excel and my system.
For example.
I tried using Decimal.Round(value,2)
. It resolves the 2nd entry from rounding off but the next problem comes in the 3rd entry. I see Principal: 773192.13
. I should see 773192.12
because that's the result in Excel and because it rounds up for the principal the result in the balance go up.
This is the result in Excel. You will notice that I put some +1
, -1
, or -2
. That's the result in my system it keeps subtracting or adding. I have -0.05
in my balance as the final result.
Excel Result
Principal: 765517.81 Interest: 128000.00 Balance: 24834482.19 Principal: 769345.40 Interest: 124172.41 Balance: 24065136.79 Principal: 773192.12 Interest: 120325.68 Balance: 23291944.67 Principal: 777058.09 Interest: 116459.72 Balance: 22514886.58 Principal: 780943.38 Interest: 112574.43 Balance: 21733943.21 Principal: 780943.09 Interest: 108669.72 Balance: 20949095.12
System Result
Principal: 765517.81 Interest: 128000.00 Balance: 24834482.19 Principal: 769345.40 Interest: 124172.41 Balance: 24065136.79 Principal: 773192.13 +1 Interest: 120325.68 Balance: 23291944.66 -1 Principal: 777058.09 Interest: 116459.72 Balance: 22514886.57 -1 Principal: 780943.38 Interest: 112574.43 Balance: 21733943.19 -2 Principal: 784848.09 Interest: 108669.72 Balance: 20949095.11 -1
My code
Dim balance As Decimal= 25600000
Dim pmtmonthlyamortization As Decimal= 893517.81
Dim interestrate As Decimal= 6.0 / 100
Dim TotPmts As Double
Dim mprincipal As Decimal
Dim minterest As Decimal
TotPmts = CDbl(Val(5))
For i = 0 To TotPmts
minterest = (balance * (interestrate / 12))
mprincipal = (pmtmonthlyamortization - minterest)
balance = (balance - mprincipal)
MessageBox.Show(minterest & vbNewLine & mprincipal & vbNewLine & vbNewLine & balance)
Next