> For the complete documentation index, see [llms.txt](https://sron.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sron.gitbook.io/docs/functions-in-sron/type-conversion-functions.md).

# Type Conversion functions

#### These are the functions which are used to convert a data of one type into another.

#### SRON provides four functions for this:

> * toBool()
> * toDouble()
> * toInt()
> * toString()

#### **1. toBool():**

This function can convert values of type 'String', 'Int' and 'Double' to type 'Bool'.

```js
{
    name : Main

    Any val 
    @ converting 'Int' type to 'Bool', if the value is larger
    @ than zero than toBool returns true otherwise false
     val = toBool(-12)
     println(val)

    @ converting 'Double' type to 'Bool', it also work same 
    @ as double
    val = toBool(123.122)
    println(val)
    
    val = toBool(0)
    println(val)
}
```

#### **OUTPUT:**

> true\
> true
>
> false

***

#### **2. toDouble():**

This function can convert values of type 'String', 'Int' and 'Bool' to type 'Double'.

```js
{
    name : Main

    String str1 = "-155.12425"

    @  converting 'String' type to 'Double'
     Double val = toDouble(str1)
     println(val)

    @  converting 'Int' type to 'Double'
     val = toDouble(970124123)
     println(val)

    @  converting 'Bool' type to 'Double'
     val = toDouble(true)
     println(val)
    
}
```

#### **OUTPUT:**

> -155.12425\
> 970124123.0\
> 1.0

***

#### **3. toInt():**

This function can convert values of type 'String', 'Double' and 'Bool' and 'Char' to type 'Int'.

```js
{
    name : Main

    String str1 = "15512425"

    @  converting 'String' type to 'Int'
     Int val = toInt(str1)
     println(val)

    @  converting 'Double' type to 'Int'
     val = toInt(970124123.2344)
     println(val)

    @  converting 'Bool' type to 'Int'
     val = toInt(false)
     println(val)

    @  converting 'Char' type to 'Int'
     val = toInt('7')
     println(val)
    
}
```

#### **OUTPUT:**

> 15512425\
> 970124123\
> 0\
> 7

***

#### **4. toString():**

This function can convert values of any type to type 'String'.

```js
{
    name : Main

    @  converting 'Int' type to 'String'
     String val = toString(2663)
     println(val)

    @  converting 'Double' type to 'String'
     val = toString(9701.133)
     println(val)

    @  converting 'Bool' type to 'String'
     val = toString(true)
     println(val)

    @  converting 'Char' type to 'String'
     val = toString('S')
    println(val)
}
```

#### **OUTPUT:**

> 2663> \
> 9701.133000> \
> true> \
> S

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://sron.gitbook.io/docs/functions-in-sron/type-conversion-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.
