Trivial fix, but replaces strings concatenations by a StringBuilder. Another change (which originated this work) is the removal of the unused local variable "type".
Added a unit test for asNumber (working branch), and another when the value of the literal is not a Number. Also verified that the exception contains parts of the text expected in the error message. The test runs fine before the patch, and after the patch.