DataType

# Integer

<div class="rst-class">

forsearch

</div>

DataType

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to store <span class="title-ref">Integer</span> values. The default value is 0. Generally you will use the <span class="title-ref">Integer</span> data type (equivalent to `Int32</api/data_types/additional_types/int32>` on 32-bit apps or `Int64</api/data_types/additional_types/int64>` on 64-bit apps) or `UInteger</api/data_types/additional_types/uinteger>` (equivalent to `UInt32</api/data_types/additional_types/uint32>` on 32-bit apps or `UInt64</api/data_types/additional_types/uint64>` on 64-bit apps). There are also other size-specific <span class="title-ref">Integer</span> data types that are available for use with external OS APIs.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                                                                                                                  | Returns                          | Shared |
|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|--------|
| `FromBinary<integer.frombinary>` | value As `String</api/data_types/string>`                                                                                                   | Integer                          | ✓      |
| `FromHex<integer.fromhex>`       | value As `String</api/data_types/string>`                                                                                                   | Integer                          | ✓      |
| `FromOctal<integer.fromoctal>`   | value As `String</api/data_types/string>`                                                                                                   | Integer                          | ✓      |
| `FromString<integer.fromstring>` | value As `String</api/data_types/string>`, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>` | Integer                          | ✓      |
| `Parse<integer.parse>`           | value As `String</api/data_types/string>`, `Optional</api/language/optional>` locale As `Locale</api/os/locale>`                            | Integer                          | ✓      |
|                                  | value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                    | Integer                          | ✓      |
| `ToBinary<integer.tobinary>`     | `Optional</api/language/optional>` minimumDigits As Integer                                                                                 | `String</api/data_types/string>` |        |
| `ToHex<integer.tohex>`           | `Optional</api/language/optional>` minimumDigits As Integer                                                                                 | `String</api/data_types/string>` |        |
| `ToOctal<integer.tooctal>`       | `Optional</api/language/optional>` minimumDigits As Integer                                                                                 | `String</api/data_types/string>` |        |
| `ToString<integer.tostring>`     | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                               | `String</api/data_types/string>` |        |
|                                  | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`, format As `String</api/data_types/string>`                                   | `String</api/data_types/string>` |        |

## Method descriptions

<div id="integer.frombinary">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.FromBinary

**FromBinary**(value As `String</api/data_types/string>`) As Integer

> Converts a text form of a binary number to an <span class="title-ref">Integer</span>.
>
> This method is `shared</api/language/shared>`.
>
> Convert "0110" to the <span class="title-ref">Integer</span> value of 6:
>
> ``` xojo
> Var value As Integer
> value = Integer.FromBinary("0110") ' value = 6
> ```

<div id="integer.fromhex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.FromHex

**FromHex**(value As `String</api/data_types/string>`) As Integer

> Converts a text form of a hexadecimal number to an <span class="title-ref">Integer</span>.
>
> This method is `shared</api/language/shared>`.
>
> Convert "ff" to the <span class="title-ref">Integer</span> value of 255:
>
> ``` xojo
> Var value As Integer
> value = Integer.FromHex("ff") ' value = 255
> ```

<div id="integer.fromoctal">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.FromOctal

**FromOctal**(value As `String</api/data_types/string>`) As Integer

> Converts a text form of an octal number to an <span class="title-ref">Integer</span>.
>
> This method is `shared</api/language/shared>`.
>
> Convert "755" to the <span class="title-ref">Integer</span> value 493:
>
> ``` xojo
> Var value As Integer
> value = Integer.FromOctal("755") ' value = 493
> ```

<div id="integer.fromstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.FromString

**FromString**(value As `String</api/data_types/string>`, `Optional</api/language/optional>` locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Integer

> Converts a string form of a decimal number to an <span class="title-ref">Integer</span>. Specify a locale to convert thousands separator.
>
> If no locale is specified, then `Locale.Raw<locale.raw>` is used.
>
> An `InvalidArgumentException</api/exceptions/invalidargumentexception>` will be raised when **value** contains anything other than an <span class="title-ref">Integer</span> (including when it is empty). Use Parse if you need to parse text that might contain non-numeric data or might be empty.
>
> This method is `shared</api/language/shared>`.
>
> Convert a number in text to an \`Integer\`:
>
> ``` xojo
> Var value As Integer
> value = Integer.FromString("42") ' value = 42
> ```
>
> This code converts a number using the US locale:
>
> ``` xojo
> Var locale As New Locale("en-US")
> Var value As Integer
> value = Integer.FromString("1,234", locale) ' value = 1234
> ```
>
> You can also use an exception to catch invalid data:
>
> ``` xojo
> ' Exception raised for invalid text, so you can handle your own
> ' special cases.
> Var value As Integer
> Try
> value = Integer.FromString("123ABC")
> Catch e As InvalidArgumentException
> value = -1 ' if data is invalid, just use -1
> End Try
> ```

<div id="integer.parse">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.Parse

**Parse**(value As `String</api/data_types/string>`, `Optional</api/language/optional>` locale As `Locale</api/os/locale>`) As Integer

> Converts the Text to an <span class="title-ref">Integer</span> value.
>
> This method is `shared</api/language/shared>`.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

Integer.Parse

**Parse**(value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Integer

> Converts the Text to an <span class="title-ref">Integer</span> value.
>
> If no *locale* is specified, then `Locale.Raw<locale.raw>` is used.
>
> Numbers are converted only if they are found at the beginning of the text. Any numbers that follow a non-numeric value are ignored. Empty text returns 0.
>
> This method is `shared</api/language/shared>`.
>
> Convert String/Text to an \`Integer\`:
>
> ``` xojo
> Var i As Integer
> i = Integer.Parse("123ABC")
> ' i = 123
> ```

<div id="integer.tobinary">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.ToBinary

**ToBinary**(`Optional</api/language/optional>` minimumDigits As Integer) As `String</api/data_types/string>`

> Converts the <span class="title-ref">Integer</span> value to a String containing its binary representation.
>
> Convert an <span class="title-ref">Integer</span> value to the binary text value:
>
> ``` xojo
> Var i As Integer = 8
> Var binary As String = i.ToBinary(4) ' binary = "1000"
> ```

<div id="integer.tohex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.ToHex

**ToHex**(`Optional</api/language/optional>` minimumDigits As Integer) As `String</api/data_types/string>`

> Converts the <span class="title-ref">Integer</span> value to a String containing its hexadecimal representation.
>
> Convert an <span class="title-ref">Integer</span> value to the hexadecimal text value:
>
> ``` xojo
> Var i As Integer = 255
> Var hex As String = i.ToHex(4) ' hex = "00FF"
> ```

<div id="integer.tooctal">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.ToOctal

**ToOctal**(`Optional</api/language/optional>` minimumDigits As Integer) As `String</api/data_types/string>`

> Converts the <span class="title-ref">Integer</span> value to a String containing its octal representation.
>
> Convert an <span class="title-ref">Integer</span> value to the octal text value:
>
> ``` xojo
> Var i As Integer = 10
> Var octal As String = i.ToOctal(4) ' octal = "0012"
> ```

<div id="integer.tostring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Integer.ToString

**ToString**(locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `String</api/data_types/string>`

> Converts the <span class="title-ref">Integer</span> to a String value using the specified *locale* and format.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

Integer.ToString

**ToString**(locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`, format As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Converts the <span class="title-ref">Integer</span> to a String value using the specified locale and format.
>
> If no *locale* is specified, then `Locale.Raw<locale.raw>` is used.
>
> Refer to the [Unicode Technical Standard \#35, appendix G (Number Format Patterns)](http://unicode.org/reports/tr35/tr35-4.html#Number_Format_Patterns) for information on how to specify a format.
>
> Convert an <span class="title-ref">Integer</span> value to a String:
>
> ``` xojo
> Var i As Integer = 42
> Var t As String = "The number is " + i.ToString
> ```
>
> Add to an <span class="title-ref">Integer</span> directly and convert the new value:
>
> ``` xojo
> Var n As Integer = 5
> Var t As String = Integer(n + 1).ToString ' t = "6"
> ```
>
> Formats the <span class="title-ref">Integer</span> value:
>
> ``` xojo
> value = 1245
> Var t As String = value.ToString ' t = "1245"
> t = value.ToString(Locale.Current, "#,###") ' t = "1,245"
> ```
>
> The format string can contain up to three sections separated by semicolons to control the output for positive, negative, and zero values independently:
>
> ``` xojo
> Var n As Integer = 1245
> Var t As String = n.ToString(Locale.Current, "#,##0;(#,##0);'Zero'")
> ' t = "1,245"
>
> n = -1245
> t = n.ToString(Locale.Current, "#,##0;(#,##0);'Zero'")
> ' t = "(1,245)"
>
> n = 0
> t = n.ToString(Locale.Current, "#,##0;(#,##0);'Zero'")
> ' t = "Zero"
> ```

## Notes

Integer values use 4 bytes for 32-bit apps and 8 bytes for 64-bit apps.

Integer values range from -2,147,483,648 to 2,147,483,647 (32-bit apps) or -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (64-bit apps).

If you assign a value that is larger (or smaller) than what the specific <span class="title-ref">Integer</span> type can hold, then the value will "overflow". This means the value will wrap around to the corresponding largest or smallest value and continue from there.

All integers on Android are 64-bit integers.

## Sample code

``` xojo
Var value As Integer
value = 42
value = value * 2
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Var</api/language/var>` command; `UInteger</api/data_types/additional_types/uinteger>` data type

</div>
