Reputation: 133
what is the easiest way to format a numpy float64 value like this:
8.928571429999999509e+02
to:
892.857
Upvotes: 2
Views: 1138
Reputation: 14945
The natural way should be numpy.set_printoptions
.
Example
>>> np.set_printoptions(precision=3)
>>> print np.array([8.928571429999999509e+02])
[ 892.857]
Upvotes: 3
Reputation: 19813
You can define a custom function:
>>> myformat = lambda x: "%.3f" % x
>>> myformat(8.928571429999999509e+02)
'892.857'
Upvotes: 2
Reputation: 223
You can use string formatters "%.3f" % 8.928571429999999509e+02
Upvotes: 2