How do you round an float(input(float_input_variable) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 ā€˜)

31st Jan 2020, 6:20 PM
Dave
5 Respostas
+ 1
let me try, thank you
31st Jan 2020, 8:49 PM
Dave
+ 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 ??
31st Jan 2020, 9:23 PM
Dave
+ 1
great! thanks again
31st Jan 2020, 9:35 PM
Dave
0
hey swim, will this code work for any input that would create the extra long decimal?
31st Jan 2020, 9:16 PM
Dave
0
price = float(input()) print(price)
22nd Mar 2023, 3:12 PM
sonu yadav
sonu yadav - avatar