---
url: >-
  /statelake/scripting-reference/functions-and-procedures/conversion-functions/strtoint.md
---

# StrToInt

**StrToInt** converts a **String** into an **Integer** data type.

If the **String** does not contain a **Integer** value, then an error will occur. You could use a **Try...Except** block or **StrToIntDef** to handle the error and provide a default value.

Declaration: Function StrToInt( const S : string) : Integer;

This example shows a successful instance and a failed instance.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  MyAmount : String;
begin
  MyAmount := '123';
 //Value will be equal to 123
  Value := StrToInt(MyAmount);
  MyAmount := '123.456';
 //In error, the result is -1 (there are decimals)
  Value := StrToInt(MyAmount);
end;
```

This function will be successful for up to 999,999,999 - anything larger will cause a minus 1 (-1) error result.

For a very large integer, you could use **StrToInt64**.
