Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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 Respostas
+ 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)