Multiplication and division in Python | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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?

2nd May 2022, 7:54 AM
Gideon Selorm Ayivi
Gideon Selorm Ayivi - avatar
6 Respostas
+ 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
2nd May 2022, 8:13 AM
NonStop CODING
NonStop CODING - avatar
+ 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)
2nd May 2022, 8:59 AM
Shadoff
Shadoff - avatar
+ 3
Please go through string formatting It just take 3 min approx and u will have a understanding & the answer
2nd May 2022, 10:17 AM
Sumit Kumar
Sumit Kumar - avatar
+ 2
It is work try it x = 63*(10/100) result = "{:.2f}".format(x) print(result)
6th Jun 2022, 1:36 AM
Rahmatullah Danish
Rahmatullah Danish - avatar
+ 1
i think this works: print(f"{63/(10/100):.2f}")
3rd May 2022, 8:40 PM
underscore
underscore - avatar
15th Jun 2022, 3:04 PM
ā•„ YIPMONG Jr ā•„
ā•„ YIPMONG Jr ā•„ - avatar