About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
qiskit.utils.detach_prefix
detach_prefix(value, decimal=None)
Given a SI unit value, find the most suitable prefix to scale the value.
For example, the value = 1.3e8
will be converted into a tuple of (130.0, "M")
, which represents a scaled value and auxiliary unit that may be used to display the value. In above example, that value might be displayed as 130 MHz
(unit is arbitrary here).
Example
>>> value, prefix = detach_prefix(1e4)
>>> print(f"{value} {prefix}Hz")
10 kHz
Parameters
- value (
float
) – The number to find prefix. - decimal (
Optional
[int
]) – Optional. An arbitrary integer number to represent a precision of the value. If specified, it tries to round the mantissa and adjust the prefix to rounded value. For example, 999_999.91 will become 999.9999 k withdecimal=4
, while 1.0 M withdecimal=3
or less.
Return type
Tuple
[float
, str
]
Returns
A tuple of scaled value and prefix.
Note
This may induce tiny value error due to internal representation of float object. See https://docs.python.org/3/tutorial/floatingpoint.html for details.
Raises
- ValueError – If the
value
is out of range. - ValueError – If the
value
is not real number.
Was this page helpful?
Report a bug or request content on GitHub.