如何在 Java 表达式中编写复利公式?
到目前为止我已经
double futurevalue = moneyin * (1+ interest) * year;
So far I have
double futurevalue = moneyin * (1+ interest) * year;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 是正确的,公式是错误的。复利计算方式如下:
其中 n 是周期数, p 是每期的“利息”(每年,如果您查看年份,
p=annual/12
和n=12
如果您查看月份,则有年利息作为输入并想要计算一年)(注意:利息是百分比值,例如
4.2
表示 4.2%)The Java is correct, the fomular plain wrong. Compund interest is calculated this way:
where n is the number of periods and p is the "interest" per period (annual, if you look at years,
p=annual/12
andn=12
if you look at month, have an annual interest as input and want to calculate for a year)(Note: interest is a percentage value, like
4.2
for 4.2%)我认为这是您遇到问题的公式的幂部分(乘以年份是不正确的)。对于整数年的简单复利,您可以使用 Math.pow() 函数是 Java SDK 的一部分。
I assume it's the power part of the formula you are having trouble with (multiplying by the year isn't right). For simple compound interest with whole numbers of years you can use the Math.pow() function that's part of the Java SDK.