0
How do you round an float(input(float_input_variable)
Hello, I am currently working on a simple calculator that Asks a user for the cost and quantity of an item that they bought from a store. My problem is that when the user inputs a quantity of: 5 and a price of $2.22 the program returns a total cost of 10.1000000001. I tried using the rounding function but to no avail. Can you tell me how to prevent the program from doing that? Thank you, Andrew Print(‘Hello! Let me calculate the cost of your purchase’) print() cost_iphone=float(input(‘How much was your iphone? ‘)) print() num_iphones=float(input(‘How many iPhones? ‘)) Print() total_cost= cost_iphone * num_iphones print() print(‘Your total cost is’, ‘$’, total_cost ‘)
5 Respuestas
+ 1
let me try, thank you
+ 1
nevermind got it bro. However, got one more question. How can I round to two decimals but keep a zero when necessary? ie: 11.10 instead of 11.1 ??
+ 1
great! thanks again
0
hey swim, will this code work for any input that would create the extra long decimal?
0
price = float(input())
print(price)