# 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

***
