减去影响我的输出贷款系统的十进制问题 [英] Decimal problems subtracting that affect my output loan system

查看:71
本文介绍了减去影响我的输出贷款系统的十进制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是在循环i的第3个条目中得到错误的小数。如果我使用计算器我得到了正确的结果,但如果我把它放在excel中我得到错误的十进制结果。我想要的是在excel和我的系统中获得相同的结果



例如。



i尝试过使用Decimal.Round(值,2)是的它解决了第二个条目的四舍五入,但下一个问题来自第三个条目



[校长:773192.13]和我需要显示的价值是

[773192.12],因为这是excel的结果,因为它为校长收集结果余额上升


这是excel的结果,你会注意到我放了一些+1或-1 -2这是我的系统中的结果它不断减去或添加我的余额中有-0.05作为最终结果



[Excel结果]

本金:765517.81关键词:128000.00余额:24834482.19

本金:769345.40关键词:124172.41余额:24065136.79

校长:773192.12关键词:120325.68余额:23291944.67

校长:777058.09关键词:116459.72余额:2 2514886.58

本金:780943.38关键字:112574.43余额:21733943.21

本金:780943.09关键字:108669.72余额:20949095.12





[系统结果]



本金:765517.81利息:128000.00余额:24834482.19

本金:769345.40利息:124172.41余额:24065136.79

本金:773192.13 +1利息:120325.68余额:23291944.66 -1

本金:777058.09利息:116459.72余额:22514886.57 -1

本金:780943.38关键词:112574.43余额:21733943.19 -2

本金:784848.09关键词:108669.72余额:20949095.11 -1



< b>我尝试过:



I always get the wrong decimal in the 3rd entry of the loop i. 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) yes it resolve the 2nd entry from rounding off but the next problem comes in the 3rd entry

[ Principal: 773192.13 ] and the value that i need to show is
[ 773192.12 ] because that's the result in excel and because it round 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 or -1 -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

What I have tried:

below is my code.


Dim balance As Double = 25600000
Dim pmtmonthlyamortization As Double = 893517.81
Dim interestrate As Double = 6.0 / 100

Dim TotPmts As Double
Dim mprincipal As Double
Dim minterest As Double

TotPmts = CDbl(Val(5))

For i = 0 To TotPmts
minterest = Decimal.Round((balance * (interestrate / 12), 2 )
mprincipal = Decimal.Round((pmtmonthlyamortization - minterest), 2 )
balance = Decimal.Round((balance - mprincipal), 2 )

MessageBox.Show(minterest & vbNewLine & mprincipal & vbNewLine & vbNewLine & balance)
Next

推荐答案

你为什么要转发这个问题?我已经给你答案了。
Why have you reposted this question? I have already given you the answer.


你的计算中有双打。这个由于缺乏准确性而导致货币计算中出现错误。如果变量要触及货币价值或用于货币计算,请使用Deci而不是双人或单人或漂浮。



你有一堆双重类型。将它们全部更改为十进制,看看会发生什么。
You've got Doubles in your calculations. This introduces errors in money calculations because of a lack of accuracy. If a variable is going to touch a money value or be used in a money calculation, use Decimal instead of double or single or float.

You've got a bunch of double types. Change them all to decimal and see what happens.


Quote:

减去影响我的输出的十进制问题贷款制度

Decimal problems subtracting that affect my output loan system



第一笔贷款规则:贷款价值永远不会确切。

这就是为什么上次付款总是需要一个特殊的处理。


First loan rule: Loan values are never exact.
That is the reason why last payment always need a special handling.

lastpmtmonthlyamortization = lastbalance + lastminterest



如果Excel每笔付款使用893517.81,很可能是不是确切的值。

所以你的问题是比较Excel和你的程序之间的不同舍入。


If Excel use 893517.81 for every payment, chances are that it is not the exact value.
So your problem is about comparing different roundings between Excel and your program.


这篇关于减去影响我的输出贷款系统的十进制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆