types.Integer.tostring
Method on every
integerpure 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
// 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
tointeger | Returns the integer itself. |
tostring | Converts the float to its string form. |
tostring | Converts the bool to its string form. |
tostring | Returns a string naming the type and identity of this weakref object itself - not of the value it points at. |
| integer | class index |