The fix
function is used to round a decimal value towards zero. It comes as part of NumPy, which is a library of the high-level programming language Python.
To access the fix
function, we must import the NumPy library at the start of the program:
import numpy
numpy.fix(x, out=None)
The fix
function takes in the following parameters:
x
- an array of floats or a single numerical value to be rounded to the nearest zero.out
- (optional) the function’s output is stored at this location.The fix
function returns an array and has the same dimensions as x
. The values are of type float
.
The following program demonstrates how to apply the fix
function on an array of floats.
The return value is printed using the built-in print
function that comes with Python.
import numpyprint(numpy.fix([4.55, 12.31, -512.2313, 0.541]))
Free Resources