# others - 在python中轻松打印浮点数？

``````
[9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999, 0.055702500000000002, 0.079330300000000006]

``````

``````
>>> import print_options

>>> print_options.set_float_precision(2)

>>> print [9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999, 0.055702500000000002, 0.079330300000000006]

[9.0, 0.05, 0.03, 0.01, 0.06, 0.08]

``````

``````
import numpy as np

np.set_printoptions(precision=2)

``````

``````
np.set_printoptions(formatter={"float_kind": lambda x:"%g" % x})

``````

``````
print ["{0:0.2f}".format(i) for i in a]

``````

``````
>>> class prettyfloat(float):

def __repr__(self):

return"%0.2f" % self

>>> x

[1.290192, 3.0002, 22.119199999999999, 3.4110999999999998]

>>> x = map(prettyfloat, x)

>>> x

[1.29, 3.00, 22.12, 3.41]

>>> y = x[2]

>>> y

22.12

``````

``````
a = [9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999, 0.055702500000000002, 0.079330300000000006]

print ["%0.2f" % i for i in a]

``````

``````
>>> print"%.2f"*len(yourlist) % tuple(yourlist)

2.00 33.00 4.42 0.31

``````
``````
print"[%s]"%",".join(map(str,yourlist))

``````

``````
[9.0, 0.053, 0.0325754, 0.0108928, 0.0557025, 0.0793303]

``````

``````
import numpy as np

x=[9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999, 0.055702500000000002, 0.079330300000000006]

print('standard:')

print(x)

print(np.around(x,decimals=2))

``````

``````
standard:

[9.0, 0.053, 0.0325754, 0.0108928, 0.0557025, 0.0793303]

[ 9. 0.05 0.03 0.01 0.06 0.08]

``````

``````
print",".join("%.2f" % f for f in list_o_numbers)

``````

``````
>>> nums = [9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999]

>>> print",".join("%.2f" % f for f in nums)

9.00, 0.05, 0.03, 0.01

``````
``````
l = [9.0, 0.052999999999999999, 0.032575399999999997, 0.010892799999999999, 0.055702500000000002, 0.079330300000000006]

``````

python 2:

``````
print ', '.join('{:0.2f}'.format(i) for i in l)

``````

python 3:

``````
print(', '.join('{:0.2f}'.format(i) for i in l))

``````

``````
9.00, 0.05, 0.03, 0.01, 0.06, 0.08

``````