Converts an object to a number.
Xis any object
X is a number of any type, then
X is a vector, matrix, list, set, or structure – in each case containing only a single element which is a number – then this number is returned in its natural data type.
X is a string, then an attempt is made to parse it as a number. If successful, the parsed number is returned in the most specific data type possible: integer, rational number, real number, or complex number (in order of decreasing specificity).
In all other cases,
number(X) returns an error.
number(❨❨9, 6, 5, 15❩❩ ⋅ ❨❨8❩, ❨12❩, ❨14❩, ❨12❩❩)
TestParse ≔ s ↦ '((x ≔ number(s)), type(x))
'("7", "39/4", "3.14159265E−2", "687 + 713j") @ TestParse
(7, integer) (9.75, rational number) (0.0314159265, real number) (687 + 713⋅i, complex number)
Type conversion functions (list)