• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • latest /
      • Expressions /
      • Convert Or Cast Expression
    Kipper Docs
    • next
    • latest
    • 0.11.0
    • 0.10.4
    • 0.9.2
    • Overview

    • Quickstart

    • Goals for Kipper

    • Supported platforms

    • Usage Examples

      • Overview

      • Type Consistency

      • Runtime Type Casting

      • Strict Compiler Inspection

      • Integrated Runtime Library

    • Variables

      • Overview

      • String Type

      • Number Type

      • Boolean Type

      • Void Type

      • Null Type

      • Undefined Type

      • Array Type

      • Overview

      • Tangled Expression

      • Arithmetic Expression

      • Assignment Expression

      • Conditional Expressions

      • Logical Expressions

      • Bitwise Expression

      • Relational Expressions

      • Convert Or Cast Expression

      • F-String Expression

      • Member Access Expression

      • Function Call Expression

      • Lambda Expression

      • Matches Expression

      • Overview

      • Expression Statement

      • If Statement

      • While Loop

      • Do-While Loop

      • For Loop

      • Compound Statement

      • Jump Statement

    • Functions

    • Interfaces

    • Classes

    • Comments

    • Built-in Functions

      • Overview

      • Compiler Setup

        • Overview

          • index

          • compiler

          • errors

          • logger

          • utils

          • config

          • index

          • index

        • Overview

        • new

        • run

        • compile

        • help

        • version

      • latest /
      • Expressions /
      • Convert Or Cast Expression
    • latest /
    • Expressions /
    • Convert Or Cast Expression

    Edit page

    Convert Or Cast Expression

    Conversion expressions convert the value of an expression to a target type using pre-defined built-in conversion functions. Such conversions are essential for using values of different types in the same expression and avoiding type errors.

    An important example of this are print function call expressions, as the print function is a built-in function that only allows a string as a parameter. Therefore, to print out a number you first have to convert it to a string.

    Syntax

    EXP as TYPE;

    Allowed conversions

    From str to num

    Converts a string to a number, if it meets the following requirements:

    • Only contains numeric characters (0 - 9)
    • Is not empty (length > 0)

    Otherwise, if the string does not meet the above requirements, it will return NaN (Not a number). In future releases, though this will throw a ConversionError.

    "203" as num; // -> 203

    From num to str

    Converts a number to an identical string representation of the number.

    203 as str; // -> "203"

    From num to bool

    Converts a number to a bool. This evaluates to true if it's a non-zero value.

    20 as bool; // -> true
    0 as bool; // -> false

    From bool to num

    Converts a bool to a number. This evaluates to 1 if it's true, otherwise it's 0.

    true as num; // -> 1
    false as num; // -> 0

    From bool to str

    Converts a string to a number. This evaluates to "true" if it's true, otherwise it's "false".

    true as str; // -> "true"
    false as str; // -> "false"
  • Developed at:

    • Releases
    • GitHub
    • Security
    • Issue Tracker
    • License
  • Copyright © 2021-2025 Luna Klatzer, 2024-2025 Lorenz Holzbauer & Fabian Baitura.
    Kipper is licensed under the GPL-3.0-or-later license.