+ 6

How to make the output of 1.00 + 2.00 to be 3.00 instead of 3.0 or 3 in python?

22nd Apr 2020, 7:45 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
15 Antworten
+ 4
print(f"{1.00 + 2.00:.2f}") #or print("{:.2f}".format(1.00 + 2.00))
22nd Apr 2020, 8:21 PM
rodwynnejones
rodwynnejones - avatar
22nd Apr 2020, 8:17 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
+ 1
I just can figure it out
22nd Apr 2020, 8:17 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
+ 1
Thank you
22nd Apr 2020, 8:17 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
+ 1
But it doesn't validate it
22nd Apr 2020, 8:21 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
+ 1
You mean you Can't pass tests?
22nd Apr 2020, 8:22 PM
Abhay
Abhay - avatar
+ 1
Tnx
22nd Apr 2020, 8:22 PM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
+ 1
Eisom use math.ceil() instead of round(). For this u first import math.
23rd Apr 2020, 5:43 AM
Raj Laxmi Verma
Raj Laxmi Verma - avatar
0
You don't need to worry about those zeros
22nd Apr 2020, 8:18 PM
Abhay
Abhay - avatar
0
Yes Abhay it doesn't pass tests
23rd Apr 2020, 6:09 AM
Moshie Seidenfeld
Moshie Seidenfeld - avatar
0
Eisom Does it still not working after using ceil()???
23rd Apr 2020, 6:11 AM
Raj Laxmi Verma
Raj Laxmi Verma - avatar
0
Print("%.2f"%(1.00+2.00)) .. This will help
24th Apr 2020, 6:43 AM
Ritika Rani
Ritika Rani - avatar
0
How do you want to use this output? Assign it to a variable?
24th Apr 2020, 6:23 PM
W-tto
0
print("%.2f"%(1.00+2.00)) here is the solution:)
27th Apr 2020, 1:09 PM
Bishal kumar
- 1
this is converting result 3.0 into 3.00 , Simply convert 3.0 to str and add another str 0 to that ,which will be 3.00 and then convert that into int,but I assume that's not what you want,also I Don't think there is anyway to get 3.00 by adding 1.00 to 2.00 maybe someone else knows about it !
22nd Apr 2020, 8:13 PM
Abhay
Abhay - avatar