+ 4
Multiplication and division in Python
When I multiply 63 by (10/100), I get 6.300000000000001 but I want the output to be 6.30. How do I do that? I'm working on a code and I want my output to be in one or two decimal places but I don't know how to do that. If I multiply the same fraction by 70, I'll get 7.0. Can someone help me?
7 Answers
+ 4
write, ( 63 * 10 ) / 100, it will just give 6.3
Alternatively, đđ
use str.format( )
do this way đđđđ
https://code.sololearn.com/cjrIf2qHWUla/?ref=app
+ 4
this will round up the resulting float number up to two digits after point. print(round(63*(10/100),2))
to make it easy to read:
x = 63*(10/100)
z = round(x,2)
print(z)
+ 3
Please go through string formatting
It just take 3 min approx and u will have a understanding & the answer
+ 2
It is work try it
x = 63*(10/100)
result = "{:.2f}".format(x)
print(result)
+ 1
i think this works:
print(f"{63/(10/100):.2f}")