The currencyToNumber function converts a currency-formatted string into a numerical value. It removes any non-digit characters except for the decimal point and then parses the cleaned string into a floating-point number. If the conversion results in a NaN value, it throws an error indicating that the input is not a valid currency string. The example usage demonstrates converting "$1,234,567" to the number 1234567.