Convert API

toNum()

Converts the passed arguments to numbers.

  • Accepts arguments as strings, numbers, arrays.
    Each value is seen as a new argument.
  • Returns a number if a single argument is passed and an array of numbers if multiple arguments are passed.
Example:
toNum(1.5);
// 1.5

toNum('1.5');
// 1.5

toNum([-1, '2', ['3', '-$4.5']]);
// [-1, 2, 3, -4.5]

toNum(1, '$2.5', [3, '4', ['$5', '-6 books']]);
// [1, 2.5, 3, 4, 5, -6]