scipp.round#
- scipp.round(x, *, decimals=0, out=None)#
Round to the given number of decimals.
Note: if the number being rounded is halfway between two numbers it will round to the nearest even number. For example 1.5 and 2.5 will both round to 2.0, -0.5 and 0.5 will both round to 0.0.
For non-zero
decimals, the implementation usesrint(x * 10**decimals) / 10**decimals, which can overflow for very large values ofxcombined with large positivedecimals. This is the same algorithm and limitation asnumpy.round().- Parameters:
- Returns:
TypeVar(_T) – Rounded version of the data passed.
See also
Examples
>>> sc.round(sc.scalar(1.5)) <scipp.Variable> () float64 [dimensionless] 2 >>> sc.round(sc.scalar(1.567), decimals=2) <scipp.Variable> () float64 [dimensionless] 1.57 >>> sc.round(sc.scalar(12345.0), decimals=-2) <scipp.Variable> () float64 [dimensionless] 12300