# Units

To avoid computation addition conversion issues, the smallest units possible are used through the API for sensitive information including currency and bandwidth.

| Information Type     | Unit  |
| -------------------- | ----- |
| Bandwidth / Data     | bytes |
| Currency / Financial | cents |

**Converting Bytes**

Throughout the dashboard, bytes values will have to commonly displayed in GB or in TB. To do this accurately and inline with our API, please use the corresponding function in your language of choice to convert bytes to kb, mb, gb, tb and vice-versa.

```python
def convert_bandwidth(value, from_unit, to_unit):
    """
    Convert digital information units between bytes (B), kilobytes (KB), megabytes (MB),
    gigabytes (GB), and terabytes (TB).

    :param value: float, the value to convert
    :param from_unit: str, the unit of the input value
    :param to_unit: str, the unit of the output value
    :return: float, the converted value
    """

    # Define the multiplier for each unit
    units = {
        'b': 1,  # bytes
        'byte': 1,  # bytes
        'kb': 2**10,  # 1 kilobyte = 1024 bytes
        'kilobyte': 2**10,  # 1 kilobyte = 1024 bytes
        'mb': 2**20,  # 1 megabyte = 1024 kilobytes
        'megabyte': 2**20,  # 1 megabyte = 1024 kilobytes
        'gb': 2**30,  # 1 gigabyte = 1024 megabytes
        'gigabyte': 2**30,  # 1 gigabyte = 1024 megabytes
        'tb': 2**40,  # 1 terabyte = 1024 gigabytes
        'terabyte': 2**40,  # 1 terabyte = 1024 gigabytes
    }

    # Convert the from_unit and to_unit to lowercase
    from_unit = from_unit.lower()
    to_unit = to_unit.lower()

    # Ensure the units entered are valid and supported
    if from_unit not in units:
        raise ValueError("Invalid 'from' unit. Supported units are b, B, KB, MB, GB, TB, kilobyte, megabyte, gigabyte, terabyte.")
    if to_unit not in units:
        raise ValueError("Invalid 'to' unit. Supported units are b, B, KB, MB, GB, TB, kilobyte, megabyte, gigabyte, terabyte.")

    # Convert the value to bytes first
    bytes_value = value * units[from_unit]

    # Convert bytes to the desired unit
    converted_value = bytes_value / units[to_unit]

    return converted_value
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://internal.developer.documentation.private.user.pingproxies.com/basic-concepts/getting-started/units.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
