- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我搜索我的问题的答案,只得到了这个:
This isn't really a Django problem, and your questions is a little unclear. You basically need to apply the compound interest formula in python to an instance of this model:
account = Account.objects.get(pk=<something>)
calc_interest = lambda value: value * account.rate
amount = account.principal
for i in xrange(12):
interest = calc_interest(amount)
amount += interest
print 'month {}: {} ({} interest)'.format(i, amount, interest)This will give you:
month 0: 1050.0 (50.0 interest) month 1: 1102.5 (52.5 interest) month 2: 1157.625 (55.125 interest) month 3: 1215.50625 (57.88125 interest) month 4: 1276.2815625 (60.7753125 interest) month 5: 1340.09564062 (63.814078125 interest) month 6: 1407.10042266 (67.0047820312 interest) month 7: 1477.45544379 (70.3550211328 interest) month 8: 1551.32821598 (73.8727721895 interest) month 9: 1628.89462678 (77.5664107989 interest) month 10: 1710.33935812 (81.4447313389 interest) month 11: 1795.85632602 (85.5169679058 interest)
如果那是正确的,我应该把这个公式放在哪里?在哪个 Django 文件中?
最佳答案
这可以是您的 Account
模型的公共(public)方法。也许是这样的:
class Account(models.Model):
#..other methods and properties here
def montly_interest(self):
amount = self.principal
calc_interest = lambda value: value * self.rate
montly = []
for i in xrange(12):
interest = calc_interest(amount)
amount += interest
montly.append((i, amount, interest))
return montly
关于python - Django 如何计算对象值的月利息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35072901/
我是一名优秀的程序员,十分优秀!