display_in_unit

Contents

display_in_unit#

class brainunit.math.display_in_unit(x, u=None, precision=None)#

Display a value in a certain unit with a given precision.

Returns the canonical "value unit" format.

Parameters:
  • x (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – The value to display.

  • u (saiunit.Unit) – The unit to display the value x in. If None, the value’s own unit is used.

  • precision (int | None) – The number of digits of precision (in the given unit, see Examples). If no value is given, numpy’s get_printoptions value is used.

Returns:

s – A string representation of x in units of u.

Return type:

str

See also

Quantity.repr_in_unit

Examples

>>> import saiunit as u
>>> u.display_in_unit(3 * u.volt, u.mvolt)
'3000. mV'
>>> u.display_in_unit(123123 * u.msecond, u.second, 2)
'123.12 s'