> For the complete documentation index, see [llms.txt](https://learn.fi-code.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.fi-code.com/overview/type-casting.md).

# Type Casting

Although fi types can be confusing, we've implement a number of typecasting functions to help ensure typing is clean and consistent.

**to\_address** -  converts a contract, key, pkh/key\_hash to an address

**to\_int** - converts mutez or nat to an int

**to\_mutez** - converts nat or int to mutez

**to\_nat** - converts mutez or int to nat

**to\_optional** - converts any type to an optional version of that type

**to\_pkh** - converts a key to a key\_hash/pkh

**to\_some** - converts an optional type to a normal type (throws an error if the value is an empty optional value)

**to\_contract** - converts a key, pkh/key\_hash or address to a contract unit. If a second type argument is provided, will type cast an address to a typed address of matching type.
