Function: to_int

Function: to_int

since 0.3.7

Usage

 to_int(any value)

Convert any value to a number.

  • Real numbers are rounded towards zero when converted to integer numbers.
  • The boolean value true becomes 1, while false is converted to 0.
  • For colors the grayscale value between 0 and 255 is returned.

Parameters

Parameter Type Description
input any type Value to convert to an integer number

Examples

 to_int(1.5)   == "1"
 to_int("15")  == "15"
 to_int(true)  == 1
 to_int(rgb(255,255,255)) == 255

Use or else to recover from errors:

 to_number("not a number") or else 0  ==  0
 to_number("123")          or else 0  ==  123

See also

to_real Convert any value to a real number
to_number Convert any value to a number