---
title: "to_int"
url: https://una-lang.org/en/docs/std/builtin/to_int/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/builtins.json
---

# to_int

A built-in method, resolved by the type of its receiver ([`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2)). Edition 0.2 and later.

```una
x.to_int() -> Int
  where x: Int
x.to_int() -> Int
  where x: F, one of I8, I16, I32, I64, U8, U16, U32, U64
```

Converts `x` to `Int`, which every value of a fixed-width type fits, so it always succeeds (`spec/18 §4`). On a `Text`, `to_int` is the prelude function (`spec/14 §1`).

## Receiver

- `Int`: an integer `x`
- `F, one of I8, I16, I32, I64, U8, U16, U32, U64`: a fixed\-width integer `x`\, of one of the eight types `I8`\, `I16`\, `I32`\, `I64`\, `U8`\, `U16`\, `U32` and `U64`

## Returns

`Int`: the value of `x` as an `Int`\, which every value of a fixed\-width type fits\, so it always succeeds.

## See also

[`to_int`](https://una-lang.org/en/docs/std/prelude/to_int/), [`to_i64`](https://una-lang.org/en/docs/std/builtin/to_i64/)

## Example

`src/shop.una`

```una
module shop

--- The largest `I64` total, widened to an `Int`, which has no largest value.
pub main() -> Unit
  uses @console: Console[print]
=
  let total: I64 = 9223372036854775807
  let more = total.to_int() + 1
  @console.print("{more}")
```

`una run .` prints:

```text
9223372036854775808
```

## Specification

- [`spec/18 §4`](https://una-lang.org/en/docs/spec/18-fixed-width-integers/#s4)
- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)

Generated from una v0.4.0 ([`docs/std/builtins.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/builtins.json), which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: [`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2).
