Reputation: 824
i have a view and i am trying to perform a simple mathematical calculation and I am getting an error that is throwing me off.
So I have a method that will take in two variabes, a decimal value and a integer. I want to take the numbers and divide the decimal by the integer. I am getting the following error and I dont know why...
this is the method
def SplitEven(record, amount):
record_count = record.count
print(record_count)
print(amount)
split_amount = amount/record_count
print(split_amount)
rounded_amount = round(split_amount, 2)
print (record_count)
print (amount)
print (split_amount)
return rounded_amount
This is the error message:
unsupported operand type(s) for /: 'str' and 'int'
C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in addTransaction
taxSplit = SplitEven(record, amount)
C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in SplitEven
split_amount = amount/record_count
Here is what comes up from the print statements:
[25/Jul/2017 16:14:10] "GET /static/css/blog.css HTTP/1.1" 404 1649
6
6
6.00
[25/Jul/2017 16:15:05] "POST /39/72/add_transaction/ HTTP/1.1" 500 83164
Upvotes: 0
Views: 71
Reputation: 7717
from decimal import Decimal
def SplitEven(record, amount):
record_count = Decimal(record.count)
split_amount = Decimal(amount)/record_count
rounded_amount = round(split_amount, 2)
return rounded_amount
Upvotes: 1