# Utility Functions

This section contains utility functions that can be used to perform various common operations in dApp development.

* `toSmallUnit`: Converts an amount in decimal units to an amount in the smallest unit of a token, given the number of decimal places. Returns a BigNumber.
* `toBigUnit`:&#x20;
  * Converts an amount in the smallest unit of a token to an amount in decimal units, given the number of decimal places. Returns a string.
  * options (optional) is an object that can contain the following properties:
    * displayDecimals (optional): number of decimal places to include in the output string (default is the given decimals).
    * mode (optional): rounding mode to use ('ceil', 'round', or 'floor', default is 'floor').
* `formatBigUnit`:
  * Used to convert a big unit amount into a format based on the specified `displayDecimals`.
  * mode (optional): rounding mode to use ('ceil', 'round', or 'floor', default is 'round').
* `calcSlippage`: Calculates the maximum amount of slippage, given an amount and a slippage percentage. base (optional) is the base number used to calculate slippage (default is 10000).
* `calcFee`: Calculates the amount of a fee, given an amount and a premium percentage. base (optional) is the base number used to calculate slippage (default is 10000).
* `calcBps`: Calculates the amount of an asset as a basis point of the total balance.
* `reverseAmountWithFee`: Used to reverse-calculate the original amount before the deduction of a fee from a given amount that includes the fee.
* `shortenAddress`: Shortens an address to a specified number of digits (default is 4).
* `shortenTransactionHash`: Shortens an transaction hash to a specified number of digits (default is 4).


---

# 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://docs.protocolink.com/protocolink-sdk/common-sdk-interfaces/utility-functions.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.
