get_si_prefix¶
- get_si_prefix(value: float, select: str = 'mu', lztol: int = 0) tuple[str, float][source]¶
Obtain the best SI unit prefix option for a numeric value.
- A "best" SI prefix from a specified prefix collection is defined by minimizing :
leading zeros (possibly to a specified tolerance limit, see lztol)
significant digits before the decimal point
, after the prefix is applied.
- Parameters:
value -- the numerical value for picking the prefix.
select -- SI prefix candidates, a substring of "yzafpnum kMGTPEZY". Defaults to 'mu'.
lztol -- leading zeros tolerance. Defaults to 0 (avoid any leading zeros when possible).
- Returns:
tuple -- (prefix_string, prefix_scale)
Examples:
e.g. for frequency value in Hz >>> get_si_prefix(10**7,select='kMGT') ('M', 1000000.0)
e.g. for flux value in Jy >>> get_si_prefix(1.0,select='um') ('', 1.0) >>> get_si_prefix(0.0,select='um') ('', 1.0) >>> get_si_prefix(-0.9,select='um') ('m', 0.001) >>> get_si_prefix(0.9,select='um',lztol=1) ('', 1.0) >>> get_si_prefix(1e-7,select='um') ('u', 1e-06) >>> get_si_prefix(1e3,select='um') ('', 1.0)