How do you round an float(input(float_input_variable) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
+ 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