Documentations - SRON
  • SRON's Official Documentation
  • Installation
  • Syntax of SRON
  • Executing a SRON code
  • Keywords in SRON
  • Comments in SRON
  • Datatypes in SRON
  • Variables in SRON
  • Memory Ownership Model
  • Operators in SRON
  • Math block
  • if elif else in SRON
  • Loops in SRON
    • For Loop
    • While Loop
    • Foreach Loop
  • Break & Continue
  • Functions in SRON
    • Print functions
    • User Input Functions
    • Type Conversion functions
    • Type Checking functions
    • Math functions
    • Char Functions
    • String Functions
    • List Functions
    • Miscellaneous functions
  • Return in SRON
  • Command Line Arguments
  • Free
  • Rotate
  • Console
  • Sample codes
  • Coding Convention
  • Frequently Asked Questions
  • Credits
  • Contact
  • Donate
Powered by GitBook
On this page
  1. Functions in SRON

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:

  • to_bool()

  • to_double()

  • to_int()

  • to_string()

1. to_bool():

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

{
    name : MAIN

    String str1 = "true"

    @ converting 'String' type to 'Bool'
     Bool val = to_bool(str1)
     println(val)

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

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

OUTPUT:

true false true


2. to_double():

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

{
    name : MAIN

    String str1 = "-155.12425"

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

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

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

OUTPUT:

-155.12425 970124123.0 1.0


3. to_int():

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

{
    name : MAIN

    String str1 = "15512425"

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

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

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

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

OUTPUT:

15512425 970124123 0 7


4. to_string():

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

{
    name : MAIN

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

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

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

    @  converting 'Char' type to 'String'
     val = to_string('S')
    
}

OUTPUT:

2663 9701.133 true S [1,2,3,4,5]


PreviousUser Input FunctionsNextType Checking functions

Last updated 6 months ago