
NumPy around(): Round to N decimal places
The numpy.around()
rounds values to n
decimal places as follows.
import numpy
x0 = numpy.around(12345.6789, 0)
x1 = numpy.around(12345.6789, 1)
x2 = numpy.around(12345.6789, 2)
x3 = numpy.around(12345.6789, 3)
x4 = numpy.around(12345.6789, 4)
x5 = numpy.around(12345.6789, 5)
print(x0) # 12346.0
print(x1) # 12345.7
print(x2) # 12345.68
print(x3) # 12345.679
print(x4) # 12345.6789
print(x5) # 12345.6789
The second argument is the number of decimal places and optional. If it is 2, around()
rounds the value to 2 decimal places and outputs 12345.68. For, 12345.678 is between 12345.67 and 12345.68 and 12345.68 is nearer.
Comments
Powered by Markdown