Parameter | Type | Description |
---|---|---|
INPUT | VALUE | The input value (any type). |
VALUE(FLOAT) | The floating-point value of the input value. |
This function returns the floating-point value of the input value or expression. The floating-point value NaN is returned for values that are not convertible to a float, such as strings that are not parse-able as floats, and lists.
If the input value is already a float, it is returned as-is. This function does not change or convert a value in-place - you must reassign the result.
The type of each of the values are most visible in a trace.
world
{
start()
{
textln("asFloat(true) = "+asFloat(true));
textln("asFloat(false) = "+asFloat(false));
textln("asFloat(0) = "+asFloat(0));
textln("asFloat(3) = "+asFloat(3));
textln("asFloat(5.75) = "+asFloat(5.75));
textln("asFloat(\"128.75\") = "+asFloat("128.75"));
textln("asFloat(\"apple\") = "+asFloat("apple"));
textln("asFloat(5 + 3) = "+asFloat(5 + 3));
local a = 3;
textln("asFloat(a) = "+asFloat(a));
textln("a = "+a);
quit;
}
}
Value | Result | |
---|---|---|
BOOLEAN[false] | > FLOAT > | FLOAT[0.0] |
BOOLEAN[true] | > FLOAT > | FLOAT[1.0] |
FLOAT[Infinity] | > FLOAT > | FLOAT[Infinity] |
FLOAT[-Infinity] | > FLOAT > | FLOAT[-Infinity] |
FLOAT[NaN] | > FLOAT > | FLOAT[NaN] |
INTEGER[0] | > FLOAT > | FLOAT[0.0] |
FLOAT[0.0] | > FLOAT > | FLOAT[0.0] |
INTEGER[10] | > FLOAT > | FLOAT[10.0] |
INTEGER[3] | > FLOAT > | FLOAT[3.0] |
FLOAT[10.0] | > FLOAT > | FLOAT[10.0] |
FLOAT[3.0] | > FLOAT > | FLOAT[3.0] |
FLOAT[10.5] | > FLOAT > | FLOAT[10.5] |
FLOAT[3.5] | > FLOAT > | FLOAT[3.5] |
INTEGER[-10] | > FLOAT > | FLOAT[-10.0] |
INTEGER[-3] | > FLOAT > | FLOAT[-3.0] |
FLOAT[-10.0] | > FLOAT > | FLOAT[-10.0] |
FLOAT[-3.0] | > FLOAT > | FLOAT[-3.0] |
FLOAT[-10.5] | > FLOAT > | FLOAT[-10.5] |
FLOAT[-3.5] | > FLOAT > | FLOAT[-3.5] |
STRING[] | > FLOAT > | FLOAT[NaN] |
STRING[ ] | > FLOAT > | FLOAT[NaN] |
STRING[0] | > FLOAT > | FLOAT[0.0] |
STRING[0.0] | > FLOAT > | FLOAT[0.0] |
STRING[10] | > FLOAT > | FLOAT[10.0] |
STRING[3] | > FLOAT > | FLOAT[3.0] |
STRING[10.0] | > FLOAT > | FLOAT[10.0] |
STRING[3.0] | > FLOAT > | FLOAT[3.0] |
STRING[10.5] | > FLOAT > | FLOAT[10.5] |
STRING[3.5] | > FLOAT > | FLOAT[3.5] |
STRING[-10] | > FLOAT > | FLOAT[-10.0] |
STRING[-3] | > FLOAT > | FLOAT[-3.0] |
STRING[-10.0] | > FLOAT > | FLOAT[-10.0] |
STRING[-3.0] | > FLOAT > | FLOAT[-3.0] |
STRING[-10.5] | > FLOAT > | FLOAT[-10.5] |
STRING[-3.5] | > FLOAT > | FLOAT[-3.5] |
STRING[apple] | > FLOAT > | FLOAT[NaN] |
STRING[banana] | > FLOAT > | FLOAT[NaN] |
STRING[NaN] | > FLOAT > | FLOAT[NaN] |
STRING[infinity] | > FLOAT > | FLOAT[Infinity] |
LIST[[]] | > FLOAT > | FLOAT[NaN] |
LIST[[BOOLEAN[true], INTEGER[3], FLOAT[5.0], STRING[orange]]] | > FLOAT > | FLOAT[NaN] |