Skip to main content
Version: 8.1

toBoolean

This function is used by Ignition's Expression language..

Description

Tries to convert value to a boolean, according to these rules:

  1. If value is a number, 0 is false and anything else is true.
  2. If value is a string, then the strings (case insensitive) "on", "true", "t", "yes", "y" are all true. The strings (case insensitive) "off", "false", "f", "no", "n" are considered false. If the string represents a number, the first rule applies. All other strings fail type casting.
  3. All other types fail type casting.

If type casting fails, an error is thrown, unless the failover argument is specified, in which case it will be used.

Syntax

toBoolean(value[, failover])

  • Parameters

    • object value - The value to type cast.

    • object failover - Optional. The failover value if type casting fails.

  • Results

    • Bool - The value type cast as a bool.

Examples

Code Snippet
toBoolean(1) //returns true
Code Snippet
toBoolean("abc", false) //returns false