I have some code that takes values from a dictionary and attempts to figure out the per unit price of an item. However, I cannot figure out how to keep the values from rounding.
If I do this:
total_price = int(item['Item Price'][1:]) #First character is a dollar sign
qty = int(item['Quantity'])
unit_price = total_price/qty
I get this error:
ValueError: invalid literal for int() with base 10: '88.75'
So, I tried float
ing the value:
total_price = int(float(item['Item Price'][1:]))
qty = int(item['Quantity'])
unit_price = total_price/qty
Which doesn't return an error, but it then rounds up and I only get whole numbers.
How can I get the actual per piece price and not a rounded value? Thanks