Showing decimal places | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Showing decimal places

When I create a formula in my code and I only want my answer to display 2 digits after the decimal, how do I write my code for it?

11th Jun 2017, 10:48 AM
Gys Coetzee
Gys Coetzee - avatar
2 Answers
+ 5
Try formatting it like this maybe: x = 3.542558582882855 print('%.2f' % x) >>> 3.54
11th Jun 2017, 8:51 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
use setprecision key word for that purpose .
11th Jun 2017, 10:49 AM
RZK 022
RZK 022 - avatar