types.Integer.tointeger
Method on every
integerReturns the integer itself.
Return value
this, unchanged. Provided so every numeric type answers the same tointeger/tofloat pair without the caller checking which one it already has.
Notes
Takes no arguments, and that arity is fixed: unlike types.String.tointeger, which takes an optional base for parsing digits out of text, the number-typed tointeger() has nothing left to parse and was registered with no room for an extra argument. (5).tointeger(16) throws a wrong-number-of-parameters error rather than silently ignoring the base.
See types.Float.tointeger for what happens when the value being converted has a fractional part, or is too large to fit in a 64-bit integer.
Example
// tointeger() on an integer is the identity conversion.
println("(42).tointeger() =", (42).tointeger())
// Unlike string.tointeger(base), the number version takes no base argument:
// this closure was registered with a fixed arity of zero real parameters.
try { (42).tointeger(16) }
catch (e) println("(42).tointeger(16) throws:", e)
println("\"2A\".tointeger(16) =", "2A".tointeger(16)) // string's own tointeger *does* take a baseOutput:
(42).tointeger() = 42
(42).tointeger(16) throws: wrong number of parameters passed to native closure 'tointeger' (2 passed, 1 required)
"2A".tointeger(16) = 42See also
tofloat | Converts the integer to a float. |
tochar | Converts the integer to a one-character string, treating it as a character code. |
tointeger | Converts the float to an integer. |
tointeger | Converts the bool to an integer. |
| integer | class index |