Quirrel4.41.0

types.Float.tostring

Method on every float
pure tostring(): any

Converts the float to its string form.

Return value

The value formatted through %g with 6 significant digits, the same formatting print uses for a float. A whole-numbered float prints with no decimal point: (3.0).tostring() gives "3", not "3.0", so on its own the string cannot tell a whole float from an integer of the same value - use type when that distinction matters.

Notes

Takes no arguments; see types.Integer.tostring for the shared arity error. The %g limit of 6 significant digits means a value like 1.0 / 3.0 prints as "0.333333", not with the full precision a float could otherwise carry.

Example

examples/types/float/tostring.nut
println("(3.0).tostring() =", (3.0).tostring())   // a whole float prints with no decimal point
println("(3.5).tostring() =", (3.5).tostring())
println("type((3.0).tostring()) =", type((3.0).tostring()))

// tostring formats through "%g" with 6 significant digits
println("(1.0 / 3.0).tostring() =", (1.0 / 3.0).tostring())
Output:
(3.0).tostring() = 3
(3.5).tostring() = 3.5
type((3.0).tostring()) = string
(1.0 / 3.0).tostring() = 0.333333

See also

tostringConverts the integer to its decimal string form.
tostringConverts the bool to its string form.
tointegerConverts the float to an integer.
floatclass index