swectral.round_digit#

swectral.round_digit(value, sig_digit, mode='round')[source]#

Round values or values in arraylike to specified significant digits.

Parameters:
valuereal number or array_like

Real number or array-like of real numbers.

Supported array-like types: tuple, list, numpy.ndarray, pandas.Series, torch.Tensor.

sig_digitint

Number of significant digits, must be at least 1.

modestr, optional

Rounding mode, choose between:

  • "round"

  • "ceil"

  • "floor"

The default is "round".

Returns:
resultfloat or tuple or list or numpy.ndarray or pandas.Series or pandas.DataFrame or torch.Tensor

Rounded value or array-like of values.

If the input is a number, returns a float. If the input is array-like, returns an object of the same type containing rounded values.

Return type:

Union[float, tuple, list, ndarray, Series, DataFrame, Tensor]

Examples

Round numbers:

>>> round_digit(130.33, 2)
>>> round_digit(0.323233, 2, 'ceil')
>>> round_digit(138323, 2, 'floor')

Round array-like of numbers:

>>> round_digit([[1111, 2222], [9999, 7777]], 2)