title: “CAST” author: “laplante@plcb.ca” date: 2023-08-07 version: “1.0.0”
Cast functions are used to transform a value from one type into another.
GoWeb provides five casting functions:
int(expression)
: converts the result of the expression into an integerfloat(expression)
: converts the result of the expression into a floating-point numberbool(expression)
: converts the result of the expression into a booleanstring(expression)
: converts the result of the expression into a stringerror(expression)
: converts the result of the expression into an errorThese casts are useful for explicit type conversion, ensuring correct behavior when working across mixed types.
res={{
i := 1;
string(i);
bool(i);
float(i);
cast::int(i);
"-";
i := 0;
string(i);
bool(i);
float(i);
cast::int(i);
"-";
i := 1.1;
string(i);
bool(i);
float(i);
cast::int(i);
"-";
i := 0.0;
string(i);
bool(i);
float(i);
cast::int(i);
"-";
i := true;
string(i);
bool(i);
float(i);
cast::int(i);
"-";
i := false;
string(i);
bool(i);
float(i);
cast::int(i);
}}.
return
res=1true11-0false00-1.1true1.11-0false00-true11-false00.
laplante@plcb.ca