Quirrel4.41.0

types.Float.tofloat

Method on every float
pure (bool|number).tofloat(): any

Returns the float itself.

Return value

this, unchanged. Nothing is lost, unlike types.Integer.tofloat, which can round a 64-bit integer down to what a 32-bit SQFloat can represent.

Notes

Takes no arguments. Provided so every numeric type answers the same tointeger/tofloat pair without the caller checking which one it already has.

Example

examples/types/float/tofloat.nut
// tofloat() on a float is the identity conversion: no rounding happens here,
// unlike Integer.tofloat() converting a value from a wider integer range.
println("(3.5).tofloat() =", (3.5).tofloat())
println("(3.5).tofloat() == 3.5 =", (3.5).tofloat() == 3.5)
println("type((3.5).tofloat()) =", type((3.5).tofloat()))
Output:
(3.5).tofloat() = 3.5
(3.5).tofloat() == 3.5 = true
type((3.5).tofloat()) = float

See also

tofloatConverts the integer to a float.
tointegerConverts the float to an integer.
tofloatConverts the bool to a float.
floatclass index