: .
:
>>> round(3.1415,2)
3.14
>>> round(1.2345678e-10, 12)
1.23e-10
round() . , .
To display, it is important which version of the display you are using. In Python 2.x and deprecated in 3.x you can use the 'e' formatting.
>>> print "%6.2e" % 1.2345678e-10
1.23e-10
or in 3.x, use:
>>> print("{:12.2e}".format(3.1415))
3.14e+00
>>> print("{:12.2e}".format(1.23456789e-10))
1.23e-10
or if you like zeros:
>>> print("{:18.14f}".format(1.23456789e-10))
0.00000000012346
source
share