OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

round


Hi

round is supposed to provide an integer when
called without any precision argument.

here is the doc:

 >>> help(round)

round(number[, ndigits]) -> number

Round a number to a given precision in decimal digits (default 0 digits).
This returns an int when called with one argument, otherwise the
same type as the number

but in some circumstances it provides a float

import numpy as np

M = np.array([[0, 9],[2, 7]], dtype=int)
np.linalg.det(M)
-18.000000000000004
round(np.linalg.det(M))
-18.0 # i was expecting an integer -18, not a float

# same problem with np.round
np.round(np.linalg.det(M))
-18.0