Reputation: 19
If some Python code's output is in format like "x.xx"
How to increase its precision ?
eg:
import math
tc= int(input())
for i in range(0,tc):
x1,y1,x2,y2,v1,v2= map(int,input().split())
#distance
# d = abs(math.sqrt( abs((x1-x2)*(x1-x2)) + abs((y1-y2)*(y1-y2)) ))
#d1
d1 = abs(math.sqrt( abs((x1-x1)*(x1-x2)) + abs((y1-0)*(y1-0)) ))
#d2
d2 = abs(math.sqrt( abs((x1-x2)*(x1-x2)) + abs((0-y2)*(0-y2)) ))
niche = d1/v1
upar = d2/v2
roundoff = float("{:.5f}".format(niche+upar))
print(roundoff)
its output is 5.5 make its output as 5.50000.
Upvotes: 1
Views: 67
Reputation: 1977
print(roundoff)
is pretty printing the float value.
So you just need to remove the float conversion:
roundoffstr = "{:.5f}".format(niche+upar)
print(roundoffstr)
Upvotes: 2