qiskit-documentation/docs/api/qiskit/0.36/qiskit.utils.detach_prefix.mdx

47 lines
1.7 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: detach_prefix
description: API reference for qiskit.utils.detach_prefix
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.utils.detach_prefix
---
# qiskit.utils.detach\_prefix
<Function id="qiskit.utils.detach_prefix" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.20/qiskit/utils/units.py" signature="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**
```python
>>> 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 with `decimal=4`, while 1.0 M with `decimal=3` or less.
**Return type**
`Tuple`\[`float`, `str`]
**Returns**
A tuple of scaled value and prefix.
<Admonition title="Note" type="note">
This may induce tiny value error due to internal representation of float object. See [https://docs.python.org/3/tutorial/floatingpoint.html](https://docs.python.org/3/tutorial/floatingpoint.html) for details.
</Admonition>
**Raises**
* **ValueError** If the `value` is out of range.
* **ValueError** If the `value` is not real number.
</Function>