+ 1

How to print a number with two zeros after a point? x2

Input: a=2.5, b=4, output: c=a*b, c= 10.00

19th Mar 2020, 11:57 AM
PUFFIN Channel
PUFFIN Channel - avatar
1 Odpowiedź
+ 5
You should not be fixed to 2 zeros, because a calculation can also give a result of e.g. 12.45912316, which you may like to shorten to 12.46. To do this task you can use round() function or you can use string interpolation with formatting like this: print(f'{12.45912316:.2f}')
19th Mar 2020, 12:16 PM
Lothar
Lothar - avatar