Forms small calculation, best way to do this
Hey,
I have this small form which is a simple mortgage calculation. The
requirement is allow the user to use comma's in their inputs and such
for example: 200,000 I am confused though how I can strip the comma
and convert the input from a u'200,000' into a int(200000) so I can do
the calculation, can anyone help?
here is the code...
from django import forms
class Calculator(forms.Form):
total = forms.CharField(label='Total Price')
down = forms.CharField(label='Down Payment')
vendor = forms.CharField(label='Vendor Take Back')
rate = forms.CharField(label='Interest Rate (%)')
period = forms.CharField(label='Amortization Period (in years)')
def calculate(self):
cleaned_data = self.cleaned_data
t = cleaned_data["total"]
d = cleaned_data["down"]
v = cleaned_data["vendor"]
r = cleaned_data["rate"]
p = cleaned_data["period"]
# total = total - down - vendor take back
t = t - d - v
# interest rate = interest rate / (100 * 12) - returns monthly
interest rate
r = r/(100 * 12)
# number of payments = period (in years) * 12
n = cleaned_data["n"] = p * 12
# finalize calculation
cleaned_data["final"] = t * ( r / (1 - (1 + r) ** (- n))) / 2
cleaned_data["final"] = round(cleaned_data["final"], 2)
return cleaned_data["final"]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home