Quirrel4.41.0

types.Integer.tostring

Method on every integer
pure tostring(): any

Converts the integer to its decimal string form.

Return value

The digits of the integer, with a leading - for a negative value. No thousands separators, no leading zeros, no format specifiers - the same text print shows for an integer.

Notes

Takes no arguments: (5).tostring(1) throws wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required).

This calls the same VM conversion as tostring(), so every built-in type has a tostring of its own; see types.Float.tostring for what a fractional part does to the output and types.Bool.tostring for true/false. null has no tostring method - see types.Null.constructor.

Example

examples/types/integer/tostring.nut
// Integer.tostring gives the decimal digits, with a leading '-' for negatives.
println("(42).tostring() =", (42).tostring())
println("(-7).tostring() =", (-7).tostring())
println("type((42).tostring()) =", type((42).tostring()))

// Only "this" is accepted; a stray argument is a native-closure arity error.
try { (5).tostring(1) }
catch (e) println("(5).tostring(1) throws:", e)
Output:
(42).tostring() = 42
(-7).tostring() = -7
type((42).tostring()) = string
(5).tostring(1) throws: wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required)

See also

tointegerReturns the integer itself.
tostringConverts the float to its string form.
tostringConverts the bool to its string form.
tostringReturns a string naming the type and identity of this weakref object itself - not of the value it points at.
integerclass index