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'.

{
    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'.

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'.

OUTPUT:

15512425 970124123 0 7


4. toString():

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

OUTPUT:

2663 9701.133000 true S


Last updated