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 uses rint(x * 10**decimals) / 10**decimals, which can overflow for very large values of x combined with large positive decimals. This is the same algorithm and limitation as numpy.round().

Parameters:
  • x (TypeVar(_T)) – Input data.

  • decimals (int, default: 0) – Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.

  • out (Variable | None, default: None) – Optional output buffer.

Returns:

TypeVar(_T) – Rounded version of the data passed.

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