Return to homepage

DOSATO

Copyright © 2024 Sebastiaan Heins

2.4 Type casting

Dosato has an autocasting system, which means that you can cast types without using a keyword.
If you want to cast a type, you can use the following syntax: (TYPE) VALUE This means that in most cases, any type can be cast to any other type.

Operation Example Explanation
int -> float make float a = (int) 1.5; // 1 Value is interpreted as int, is floored.
int -> string make string a = (int) 1; // "1" Value is interpreted as string.
float -> string make string a = 1.5; // "1.5" Value is interpreted as string.
array -> string make string a = [1,2,3,4,5] // "[1, 2, 3, 4, 5]" Value is interpreted as string nicely formatted.
string -> int make int a = "Hello!"; // 6 Value is the length of the string.
array -> int make int a = [1,2,3,4,5] // 5 Value is the length of the array.